android development: how does my intent / icon get added to user's list like other social media in Android

209 views Asked by At

I would like to allow users to highlight text and post it to my web site. Is there a way to create an Android Intent running as a service which will show up on the social media / share list that appears in the Android system?

You know, when the user selects a picture and then the three dotted share icon appears and gives a list? How can I get my application's intent and icon added to the list just as the Twitter, FB etc. ones that show up?

1

There are 1 answers

0
Prerak Sola On BEST ANSWER

To receive data from an external application in your application vis Share functionality, you need to create an activity in your application which will accept the incoming data. Add the following details in AndroidManifest.xml for the Activity which will accept the data:

<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>
</activity>

So , now if any application, shares a single image, your application will be visible in the list, and if the user selects your application, ui.MyActivity activity will be launched. You can change or add multiple mimeType as per your requirement.

Also, you can add/change action as MULTIPLE_SEND to receive multiple shared files.

Once this is done, in onCreate() method of your activity, you can fetch the data in the following manner:

void onCreate (Bundle savedInstanceState) {
    ...

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    //Play with the data, as per your need
    ...
}

You can get more details regarding this, in the Official Documentation