How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

后端 未结 12 1911
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 01:08

How can you filter out specific apps when using the ACTION_SEND intent? This question has been asked in various ways, but I haven\'t been able to gather a

12条回答
  •  梦谈多话
    2020-11-22 01:32

    I had same problem and this accepted solution didn't helped me, if someone has same problem you can use my code snippet:

    // example of filtering and sharing multiple images with texts
    // remove facebook from sharing intents
    private void shareFilter(){
    
        String share = getShareTexts();
        ArrayList uris = getImageUris();
    
        List targets = new ArrayList<>();
        Intent template = new Intent(Intent.ACTION_SEND_MULTIPLE);
        template.setType("image/*");
        List candidates = getActivity().getPackageManager().
                queryIntentActivities(template, 0);
    
        // remove facebook which has a broken share intent
        for (ResolveInfo candidate : candidates) {
            String packageName = candidate.activityInfo.packageName;
            if (!packageName.equals("com.facebook.katana")) {
                Intent target = new Intent(Intent.ACTION_SEND_MULTIPLE);
                target.setType("image/*");
                target.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);
                target.putExtra(Intent.EXTRA_TEXT, share);
                target.setPackage(packageName);
                targets.add(target);
            }
        }
        Intent chooser = Intent.createChooser(targets.remove(0), "Share Via");
        chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[targets.size()]));
        startActivity(chooser);
    
    }
    

提交回复
热议问题