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.