Android共享意图Twitter:如何仅通过Tweet或Direct Message进行共享? [英] Android share intent Twitter: How to share only by Tweet or Direct Message?

查看:226
本文介绍了Android共享意图Twitter:如何仅通过Tweet或Direct Message进行共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要通过推文共享图像.

I need to share an image via only Tweet.

这是我的代码

Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        if (mInsertableToGallery) {
            mInsertableToGallery = false;
            mInsertedImagePath = MediaStore.Images.Media.insertImage(getContentResolver(), mShareImage,
                    getResources().getString(R.string.app_name) + System.currentTimeMillis(), getResources().getString(R.string.app_name));
        }
        // share only 5 specific apps:
        List<Intent> targetedShareIntents = new ArrayList<>();
        List<ResolveInfo> resInfos = getPackageManager().queryIntentActivities(shareIntent, 0);
        if (!resInfos.isEmpty()) {
            for (ResolveInfo resolveInfo : resInfos) {
                String packageName = resolveInfo.activityInfo.packageName;
                Intent targetedShareIntent = new Intent(Intent.ACTION_SEND);
                targetedShareIntent.setType("image/*");
                targetedShareIntent.setPackage(packageName);
                targetedShareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mInsertedImagePath));
                if (TextUtils.equals(packageName, "com.facebook.katana") //fb
                ||TextUtils.equals(packageName, "com.instagram.android") //instagram
                ||TextUtils.equals(packageName, "jp.naver.line.android") //line
                ||TextUtils.equals(packageName, "com.google.android.apps.plus") // plus
                ||TextUtils.equals(packageName, "com.twitter.android")) // twitter
            {
                targetedShareIntents.add(targetedShareIntent);
            }

            }
        }
        Intent chooser = Intent.createChooser(targetedShareIntents.remove(0), "");
        chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
        startActivity(chooser);

我得到结果:

单击"Android系统"时,Twitter共享弹出窗口:

When click "Android System", Twitter share popup:

我想要什么:

  1. 如何仅通过推文或直接消息通过Twitter分享?

  1. How to share via Twitter only by Tweet or Direct Message ?

如何更改标题&共享项目的图标.从Twitter共享项目从"Android系统"到"Tweet"?

How to change title & icon of share item. Ex Twitter share item from "Android System" to "Tweet"?

推荐答案

我无法同时将Tweet和Direct Message都放在前面,但是下面的代码将使您要么在其中.实际上,您可以将两者都放在最前面,但是两者都以相同的名称"Tweet"出现,因此它无法使用. 我还包括了facebook,insta和tumblr. 要获得直接消息"代替tweet,请将com.twitter.android.composer.ComposerActivity替换为com.twitter.android.DMActivity.要同时获得两者,请为DMActivity添加另一个"if".

I couldn't manage to get both Tweet and Direct Message to the front but the following code will get you either one there. Actually you can get both to the front but both appears with same name "Tweet" so its kind of unusable. I have also included facebook, insta and tumblr. To get Direct Message in place of tweet replace com.twitter.android.composer.ComposerActivity with com.twitter.android.DMActivity. To get both add another ' if ' for DMActivity.

不能肯定地说,但我认为您不能为应用程序更改软件包的图标.

Can't say surely but I don't think you can change the Icon of the package for your app.

List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("image/jpeg");//("text/plain");
        Uri uri = Uri.fromFile(outFile);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0);
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
            targetedShareIntent.setType("image/jpeg");
            targetedShareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            if(TextUtils.equals(packageName,"com.facebook.katana")|TextUtils.equals(packageName,"com.instagram.android")
                    |TextUtils.equals(packageName,"com.tumblr")) {
                targetedShareIntent.setPackage(packageName);
                targetedShareIntents.add(targetedShareIntent);
            }
            if(TextUtils.equals(resolveInfo.activityInfo.name,"com.twitter.android.composer.ComposerActivity")) {
                targetedShareIntent.setPackage(packageName);
                targetedShareIntent.setClassName(
                        resolveInfo.activityInfo.packageName,
                        resolveInfo.activityInfo.name);
                targetedShareIntents.add(targetedShareIntent);
            }
        }
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
        startActivity(chooserIntent);

这篇关于Android共享意图Twitter:如何仅通过Tweet或Direct Message进行共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆