[英]Android - Is there a foolproof way to only show possible EMAIL clients?
In android, you can send an email via the Intent.ACTION_SEND intent, but this will bring up messaging and other things (even if you specify a type of text/plain). 在android中,您可以通过Intent.ACTION_SEND意向发送电子邮件,但这将显示消息传递和其他内容(即使您指定了文本/纯文本类型)。
If you want to the user to only see possible EMAIL clients, is there a foolproof, robust way to do that? 如果您希望用户仅查看可能的EMAIL客户端,是否有一种万无一失,强大的方法来做到这一点?
Use ACTION_SENDTO
and a mailto:
Uri
pointing to the email address you want. 使用
ACTION_SENDTO
和mailto:
Uri
指向所需的电子邮件地址。
If you do not have an email address, then your app should not be trying to limit the user to email. 如果您没有电子邮件地址,则您的应用不应尝试限制用户发送电子邮件。 Please let the user share what the user wants how the user wants.
请让用户分享用户想要的东西。
BTW, the MIME type is text/plain
, not plain/text
. 顺便说一句,MIME类型是
text/plain
,而不是plain/text
。 There's a snippet for ACTION_SEND
floating around that has the wrong MIME type. 有一个用于
ACTION_SEND
的代码段,该代码段具有错误的MIME类型。
The short answer is no, any application can have itself listed. 简短的答案是不,任何应用程序都可以列出自己。 The system looks for Intent Filters that match what application can handle it.
系统会寻找与应用程序可以处理的内容匹配的意图过滤器。 With experimentation you may be able to reduce the number of applications that say it can handle the intent or you could try to make an explicit Intent, directing directly at GMail or EMail, etc.
通过实验,您可能能够减少表示可以处理该意图的应用程序的数量,或者尝试直接在GMail或EMail等处创建明确的Intent。
Have you tried message/rfc822
as the MIME type? 您是否尝试过将
message/rfc822
作为MIME类型?
See first comment: http://mobile.tutsplus.com/tutorials/android/android-email-intent/ 看到第一条评论: http : //mobile.tutsplus.com/tutorials/android/android-email-intent/
See also this: Send an email in Android selecting only email apps AND specifying attachment mime type 另请参阅: 在Android中发送电子邮件,仅选择电子邮件应用程序并指定附件mime类型
That narrows down to Gmail and Bluetooth in my phone. 这将范围缩小到我手机中的Gmail和蓝牙。
message/partial
seems to do the same. message/partial
似乎也是如此。
I don't know if this works for all phones but seems to be a viable alternative. 我不知道这是否适用于所有手机,但似乎是一个可行的选择。
Here's test code: 这是测试代码:
private void sendEmail()
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "foo.bar@invalid.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "From Test app");
intent.putExtra(Intent.EXTRA_TEXT, "Test test test");
intent.setType("message/rfc822");
startActivity(intent);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.