Make my activity one of the mail apps shown in the

2019-09-14 10:25发布

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条回答
时光不老,我们不散
2楼-- · 2019-09-14 11:10

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.

查看更多
劫难
3楼-- · 2019-09-14 11:11

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.

查看更多
登录 后发表回答