Intent createChooser stop that does not work in Marshmallow

I had code in a pre-Marshmallow application that selected only some of the installed applications that implement Intent.ACTION_SENDand show a Intent.createChooserwith only these. This is the full code:

Intent actionSendIntent = new Intent();
actionSendIntent.setAction(Intent.ACTION_SEND);
actionSendIntent.setType("text/plain");
List<ResolveInfo> resInfos = getPackageManager().queryIntentActivities(actionSendIntent, 0);

List<Intent> shareIntents = new ArrayList<Intent>();
if(!resInfos.isEmpty()){
    for(ResolveInfo res : resInfos){
        final String packageName = res.activityInfo.packageName;
        if (packageName.contains("com.twitter.android") ||
                packageName.contains("com.facebook.katana") ||
                packageName.contains("com.facebook.lite") ||
                packageName.contains("com.whatsapp")) {
            final Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, "text");
            intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
            intent.setPackage(packageName);
            shareIntents.add(intent);
        }
    }
}
Intent chooserIntent = Intent.createChooser(shareIntents.remove(0), shareText);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, shareIntents.toArray(new Parcelable[]{}));
startActivity(Intent.createChooser(chooserIntent, shareText));

This code does not work in Marshmallow and shows the Android System as the only option available ... does anyone know why?

+4
source share

Source: https://habr.com/ru/post/1620601/


All Articles