简体   繁体   中英

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

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM