tags:

views:

36

answers:

2

How can I create a custom activity that can be chosen by the user via the share option when viewing the photo gallery? I have options like "Share with Facebook, Twitter, FlickR" etc. But I want to add my own option in there.

i.e. Go to "Photos", then click the "Share" button. You will be presented with a bunch of share providers. What do I need to do to get my activity in there?

+1  A: 

I trigger this dialog with invoking the following code:

Intent shareImage = new Intent();
shareImage.setAction(Intent.ACTION_SEND);
String mimeTyp = "image/png";
shareImage.setType(mimeTyp);
shareImage.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(shareImage, "Share Image"));

this shows that you need to create an Intent Filter for the action send and all the image types that you want to catch.

I haven't tested it but I think you can add the following intent filter to the activity that you want to handle the send image intent:

<intent-filter ...>
   <action android:name="android.intent.action.SEND" />
   <data android:mimeType="image/png" android:scheme="http"... />
   .
   .
   .
</intent-filter>

I'm not totally sure about the complete configuration of the filter but I think you can figure out the rest yourself.

Janusz
But this is just to start an action is it not? I want to insert my own activity into the share image activity. So if the user goes to "Photos" on their phone, then clicks "Share", they get a list of applications they can share their photo with. I want my application to be in there.
Mark Ingram
A: 

After taking a look at the built-in Mail application I spotted this section in the AndroidManifest.xml (thanks Janusz).

<intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

My app now shows up in the list :)

Mark Ingram
Now your app will also show up in every other send list. If your app is only for image sharing you should use the correct mime type.
Janusz
Yeah thanks Janusz - I've changed it just to android:mimeType="image" now.
Mark Ingram