views:

63

answers:

2

When clicking an email address from a browser or contacts app...

Is there any way for my app to show a mail client in the intent list?

+2  A: 

As you can see from the Mail application's source, having your application catch the intent is as simple as adding the intent-filter to your AndroidManifest.xml inside your mail composition activity definition.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="mailto" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

You can see that the <data> tag specifies to handle mailto: links. The BROWSABLE category means it can be launched from the browser.

K-9 Mail is similar, except using the SENDTO action only with the DEFAULT category, and the VIEW action only with the BROWSABLE category.

Andrew Koester
How can the android system know which of my activities is the compose mail activity?
cjavapro
@cjavapro Updated my answer with examples from both the Mail app and K-9.
Andrew Koester
Works perfectly! Thanks! Also thanks for the link to the mail app source. I should be able to find the compose layout xml to answer my other question
cjavapro
+1  A: 

You need to use an Intent Filter. Check out http://developer.android.com/guide/topics/intents/intents-filters.html for more information. You usually declare these in your manifest file. The intent I believe you're looking for is Intent.ACTION_SEND.

Chris Thompson