开发者

How to create a photo sharing activity?

开发者 https://www.devze.com 2023-01-14 02:55 出处:网络
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 a

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 nee开发者_StackOverflow中文版d to do to get my activity in there?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号