Android: 一些分享意图(WeChat, Url2Pdf)在自定义后没有立即显示

Android: Some Share Intents (WeChat, Url2Pdf) not shown right after Customizing

所以我尝试自定义通过 Intent.ACTION_SEND 显示的应用程序,结果非常好,除了微信和 UrlToPDF。它显示为 "Android-System" 而不是 "WeChat"。如果我单击它,它会打开另一个意图,其中微信应用程序正确显示但单独显示,没有其他应用程序。我做错了什么?

代码如下:

shareIntent = new Intent(Intent.ACTION_SEND);

shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, forecastStr+" #SunshineApp");

final PackageManager pm = getActivity().getPackageManager();
final List<ResolveInfo> resInfo = pm.queryIntentActivities(shareIntent, 0);

ArrayList <String> packageAllowed = new ArrayList();
packageAllowed.add("com.twitter.android");
packageAllowed.add("com.facebook.katana");
packageAllowed.add("com.google.android.gm");
packageAllowed.add("com.whatsapp");
packageAllowed.add("com.evernote");
packageAllowed.add("ch.threema.app");
packageAllowed.add("com.skype.raider");
packageAllowed.add("com.tencent.mm");
packageAllowed.add("com.tencent.mm.ui.tools.ShareToTimeLineUI");

ArrayList <String> packageSum = new ArrayList();

if (!resInfo.isEmpty()) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    for (ResolveInfo resolveInfo : resInfo) {
        String packageName = resolveInfo.activityInfo.packageName;

        if(packageAllowed.contains(packageName)){
            Intent intent=new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, "Text");
            intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");

            intent.setPackage(packageName);
            targetedShareIntents.add(intent);
        }
    }

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

尝试另外设置组件名称:

if(packageAllowed.contains(packageName)){
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, "Text");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");

    // This is new!!!
    intent.setComponent(new ComponentName(packageName, resolveInfo.activityInfo.name)); 

    intent.setPackage(packageName);
    targetedShareIntents.add(intent);
}