Intent选择器过滤会覆盖操作名称

时间:2016-09-27 12:10:17

标签: android android-intent

使用this answer中的代码,我构建了一个图像共享意图选择器,它应该只显示一组特定的应用程序(Instagram,Twitter,Facebook等等)。

效果很好,但显示应用程序的显示名称。

使用此代码:

    public static void startImageSharingIntent(Activity caller, List<String> possiblePackagesNames, Uri imgUri) {
    try {
        List<Intent> targetedShareIntents = new ArrayList<Intent>();
        Intent intentTemplate = new Intent(Intent.ACTION_SEND);
        intentTemplate.setType("image/*");

        List<ResolveInfo> resInfo = caller.getPackageManager().queryIntentActivities(intentTemplate, 0);
        if (!resInfo.isEmpty()) {
            for (ResolveInfo info : resInfo) {
                if (possiblePackagesNames.contains(info.activityInfo.packageName.toLowerCase())) {
                    Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/*");

                    targetedShare.putExtra(Intent.EXTRA_STREAM, imgUri);

                    targetedShare.setPackage(info.activityInfo.packageName);
                    //adding bottom line puts the app name in the intent
                    targetedShare.setClassName(info.activityInfo.packageName, info.activityInfo.name);

                    targetedShareIntents.add(targetedShare);
                }
            }

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

如果我对行targetedShare.setClassName(info.activityInfo.packageName, info.activityInfo.name);发表评论,那就是结果选择器:

enter image description here

取消注释显示:

enter image description here

在第一个显示&#34; Android系统&#34;选项,这是错误的;但在第二个中,Twitter的不同行为的标签仅重命名为Twitter。

有没有办法避免使用&#34; Android系统&#34;选项但不覆盖默认意图名称?

0 个答案:

没有答案
相关问题