Android:receiving Data from the Send Intent, share your app registration system

Source: Internet
Author: User
Tags home screen

When users click Share in the System album, they can share the image through our own app.

1. Registration

Mainly in the Androidmanifest.xml, the activity registered Intent-filter, such as:

<activity android:name= ". UI. MyActivity ">    <intent-filter>        <action android:name=" Android.intent.action.SEND "/>        <category android:name= "Android.intent.category.DEFAULT"/>        <data android:mimetype= "image/*"/>    </intent-filter>    <intent-filter>        <action android:name= "Android.intent.action.SEND"/ >        <category android:name= "Android.intent.category.DEFAULT"/>        <data android:mimetype= "text/ Plain "/>    </intent-filter>    <intent-filter>        <action android:name=" Android.intent.action.SEND_MULTIPLE "/>        <category android:name=" Android.intent.category.DEFAULT "/>        <data android:mimetype= "image/*"/>    </intent-filter></activity>

2. Handling:

In activity, get the text and pictures in intent.

void OnCreate (Bundle savedinstancestate) {...//Get intent, action and MIME type Intent intent = getintent ();    String action = Intent.getaction ();    String type = Intent.gettype (); if (Intent.ACTION_SEND.equals (ACTION) && type! = null) {if ("Text/plain". Equals (type)) {handle SendText (Intent); Handle text being sent} else if (Type.startswith ("image/")) {handlesendimage (intent);//Handle Sin GLE image being sent}} else if (Intent.ACTION_SEND_MULTIPLE.equals (ACTION) && type! = null) {i     F (Type.startswith ("image/")) {handlesendmultipleimages (intent);//Handle multiple images being sent} } else {//Handle other intents, such as being started from the home screen} ...}    void Handlesendtext (Intent Intent) {String Sharedtext = Intent.getstringextra (Intent.extra_text); if (sharedtext! = null) {//Update UI to reflect text being shared}}void HandlEsendimage (Intent Intent) {uri Imageuri = (URI) Intent.getparcelableextra (Intent.extra_stream); if (Imageuri! = null) {//Update UI to reflect image being shared}}void handlesendmultipleimages (Intent Intent    ) {arraylist<uri> Imageuris = Intent.getparcelablearraylistextra (Intent.extra_stream); if (Imageuris! = null) {//Update UI to reflect multiple images being shared}}

Read more:

Simple example: http://code.tutsplus.com/tutorials/android-sdk-receiving-data-from-the-send-intent--mobile-14878

More exchanges, Android Development Alliance QQ Group:272209595


Android:receiving Data from the Send Intent, share your app registration system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.