0

I have to sharing the image to Facebook, Whatsapp and Twitter but while sharing only Facebook is coming other app is not coming. Last month it was working but suddenly it stop working. What mistake have I made?

    //get file uri
    Uri myImageFileUri = FileProvider.getUriForFile(this,
            getApplicationContext().getPackageName() + ".provider", file);

    //create a intent for facebook, twitter, whatsapp
    List<Intent> intentShareList = new ArrayList<Intent>();
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("image/png");
    List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(shareIntent, 0);
    for (ResolveInfo resInfo : resolveInfoList) {
        String packageName = resInfo.activityInfo.packageName;
        String name = resInfo.activityInfo.name;
        if (packageName.contains("com.facebook") ||
                packageName.contains("com.twitter.android") || packageName.contains("com.whatsapp")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.putExtra(Intent.EXTRA_STREAM, myImageFileUri);
            intent.setType("image/png");
            intentShareList.add(intent);
        }
    }

    if (intentShareList.isEmpty()) {
        // no apps install
    } else {
        Intent chooserIntent = Intent.createChooser(intentShareList.remove(0), "Share with");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentShareList.toArray(new Parcelable[]{}));
        startActivity(chooserIntent);
    }

intentShareList in that all three app is been added but while share bottomsheet is been opened in that only Facebook app is there.

halfer
  • 19,471
  • 17
  • 87
  • 173
Atul Dhanuka
  • 1,425
  • 5
  • 20
  • 54

1 Answers1

0

Android 11 and above need <queries> element for package visibility. You have to define it in your app's manifest, with each package name you want to interact with.

<manifest>
    <queries>
        <package android:name="com.twitter.android" />
        <package android:name="com.facebook.orca" />
        <package android:name="com.whatsapp" />
    </queries>
...
...
</manifest>
Praveen
  • 2,453
  • 2
  • 5
  • 19