both labels shows “WeChat” when share to wechat friend and timeline

可紊 提交于 2020-01-14 02:08:26

问题


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.


回答1:


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

                    targetedShareIntents.add(extraIntents);


来源:https://stackoverflow.com/questions/20840598/both-labels-shows-wechat-when-share-to-wechat-friend-and-timeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!