Adding custom actions to Android sheet

I have an application where the user needs to be able to transmit some text. Now I want to provide default sharing options for the plain text that Android provides. I do it with the following code:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.setType("text/plain");

Intent chooser = Intent.createChooser(sendIntent, "Share");
startActivity(chooser);

      

It will look something like this:

Share DialogSource: http://developer.android.com/training/basics/intents/sending.html

But now I would also like to have another option in the Select-Access Services dialog box that triggers its own action in my own code. Namely, I want the user to be able to love the post. So besides sharing via SMS, email, FB, whatever, I would like to have another item at the top of this list that says "Add to favorites" (including an icon, if possible).

So my question is, is this possible?!? And if like :)

Any advice is appreciated!

+3


source to share


1 answer


Intent filters inform the system that the application component intends to accept. Similar to how you created an intent with an ACTION_SEND action in Sending Simple Data to Other Applications, you create intent filters to be able to receive intents with this action. You define an intent filter in your manifest using this element. For example, if your application handles getting text content, one image of any type, or multiple images of any type, your manifest would look like this:

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

      



from Getting simple data from other applications: update your manifest

0


source







All Articles