skip to Main Content

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.

2

Answers


  1. 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>
    
    Login or Signup to reply.
  2. Starting from Android 11, Google added some more restrictions on Package Visibility to enforce more privacy on user’s device and you cannot be able to read which app are installed on user’s device so the system will not be able to identify which app can open the intent. Now you need to add this permission in your manifest file

     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
            tools:ignore="QueryAllPackagesPermission" />
    

    After I added it, now it’s creating chooser for me in Android 13. Remember the above permission is considered by Playstore as a Sensitive Permission and after you add the above permission and deploy your app to playstore, you will be needed to fill the permission declaration form. Read more on the Query All Packages Package Visibility Privacy Policy.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search