Domanda

i've a android app to share message to WeChat(without sdk).

When i directly use the StartChooser method, the display-name 'Send to Moment' and 'Send to Chat' display well.

But when i want to remove the apps i donot need using a intent filter as follows, there's problem that both display-name show 'WeChat' rather than 'Send to Moment' and 'Send to Chat'.But at the same time,their icon are right!

Who can tell me how to get the right display label?? Thank you!

Intent it = new Intent(Intent.ACTION_SEND);
it.setType("image/*");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(it, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if (!resInfo.isEmpty()) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    for (ResolveInfo info : resInfo) 
    {
        Intent targeted = new Intent(Intent.ACTION_SEND);
        targeted.setType("image/*");
        ActivityInfo activityInfo = info.activityInfo;

        if (activityInfo.packageName.contains("tencent.mm") || etc..) 
        {
            targeted.setClassName(activityInfo.packageName, activityInfo.name);
            targeted.setPackage(activityInfo.packageName);

            targeted.putExtra(Intent.EXTRA_TEXT, "share text");
            targeted.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            targetedShareIntents.add(targeted);
        }
    }

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

!!! update !!! :

if the wechat intent being placed in "Intent.createChooser", the label shown is right, but shown wrong label when placed in "EXTRA_INITIAL_INTENTS".

UPDATE2: I find the answer at How to make an intent with multiple actions. Using LabeledIntent will solve the problem.Over.

È stato utile?

Soluzione

Here is how I get it to work.

CharSequence label = info.loadLabel(getPackageManager());
Intent extraIntents = new LabeledIntent(targeted, activityInfo.packageName, label, info.icon);

targetedShareIntents.add(extraIntents);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top