Android - Is there a foolproof way to only show po

2019-08-14 20:06发布

问题:

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

If you want to the user to only see possible EMAIL clients, is there a foolproof, robust way to do that?

回答1:

Use ACTION_SENDTO and a mailto: Uri pointing to the email address you want.

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. There's a snippet for ACTION_SEND floating around that has the wrong MIME type.



回答2:

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.



回答3:

Have you tried message/rfc822 as the MIME type?
See first comment: 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

That narrows down to Gmail and Bluetooth in my phone. message/partial seems to do the same.

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);
}