Michał Kowalczuk
Michał Kowalczuk

Reputation: 955

Adding action visible only in specific applications to ACTION_SEND?

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)?

Upvotes: 5

Views: 677

Answers (1)

marmor
marmor

Reputation: 28179

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);

Upvotes: 2

Related Questions