I'm using:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpeg");
(...)
to share image generated in my app. I would like to add custom action (save image to gallery) to intent created by
Intent.createChooser(i, "...");
I was thinking about adding activity with intent-filter for android.intent.action.SEND action, but this will make my activity visible and available to all applications. I could change setType("image/jpeg") to setType("image/*") and add
<data android:mimeType="image/foobar">
to intent-filter, but this will make my activity visible to all applications that asks for image/*.
Is there any way to filter action visibility by caller package name (or something else, that could distinguish my application from other)?
Android has a nice solution for this requirement, the trick is Intent.EXTRA_INITIAL_INTENTS
:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");
List<Intent> myAddedIntents = new ArrayList<Intent>();
Intent myIntent = new Intent(...);
myAddedIntents.add(myIntent);
Intent chooserIntent = Intent.createChooser(intent, "Send via:");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
myAddedIntents.toArray(new Parcelable[] {}));
startActivity(chooserIntent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With