I have a simple code to share photos through external apps that have been working as expected in previous Android versions. But we are getting some reports saying that users can not share photos with their apps because only some of them appears in the share sheet.
We did some tests in different phones (with Android 10), and the results is that there are only like 3 or 4 app available to share, and it depends on the phone. For instance, in some phones Gmail is shown, but no in other. In those where Gmail appears, it works correctly.
Any idea why?
This is how Uri looks: content://com.MyPackageName.fileprovider/external_cache/test2014_000000059279.jpg
This is how mime looks: image/jpeg
Here is the code, I've simplified it a bit.
public void shareViaIntent(Context context, Uri uri, String mimeType, CharSequence shareTitle) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType(mimeType);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read file from temp cache path of our app
shareIntent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.shared_text));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
final ArrayList<Intent> shareIntents = getExternalShareIntents(context, shareIntent);
Intent chooserIntent = Intent.createChooser(target, shareTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, shareIntents.toArray(new Parcelable[]{}));
context.startActivity(chooserIntent);
}
private ArrayList<Intent> getExternalShareIntents(Context context, Intent shareIntent) throws Throwable {
final List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(shareIntent, 0);
final ArrayList<Intent> shareIntents = new ArrayList<>();
for (ResolveInfo resolveInfo : resolveInfos) {
final String packageName = resolveInfo.activityInfo.packageName;
if (packageName.equals(buildInfo.getApplicationId())) {
continue;
}
Intent intent = new Intent(shareIntent);
intent.setComponent(new ComponentName(packageName, resolveInfo.activityInfo.name));
shareIntents.add(intent);
}
return shareIntents;
}
And here you can see the behavior changes depending on the phone..
Thanks in advance