1

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?

user655489
  • 1,316
  • 3
  • 14
  • 21

3 Answers3

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I take it the mailto (when you have an email address) doesn't break in weird ways out in the wild... as for when I don't have an email address... I'm afraid that I still want it sent via email, based on the context and material. mime-type - thanks CW - I got that backwards from memory - doh – user655489 Nov 18 '11 at 18:34
  • Just saw that you had a link there, cw, so I went and took a look. Well, I know in one case I won't have the email address, but I know it needs to be sent via email based on the size and content. However, the other case could work well in the context of an sms if the user wanted to send it that way. – user655489 Nov 18 '11 at 18:46
  • @user655489: "but I know it needs to be sent via email based on the size and content" --the user could share it via DropBox, or upload it to Evernote, or use any number of other apps and online storage/sharing options. Big may mean "not SMS", and the SMS client will probably tell them that. But big does not mean email. – CommonsWare Nov 18 '11 at 18:50
  • hmm, I admit I hadn't considered that! I'll go see if those two handle the limited html stuff android can send in its spannable thing. – user655489 Nov 18 '11 at 19:10
  • @user655489: If you're sending HTML, use `text/html`. – CommonsWare Nov 19 '11 at 00:51
  • this is for plain text. It's just your note got me to thinking about the other case. messaging and other "nuisance" things (in this context) don't respond to text/html mime type, so it wasn't an issue in that case when there is something that supports text/html... but Bluetooth, btw, says it does handle the text/html mime-type, even though it can't handle the spannable stuff Android creates when you use the handful of html tags that html.FromHtml supports ("Unsupported content format" - even though it responded to the intent! but I seriously digress) – user655489 Nov 19 '11 at 03:36
0

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.

Dan S
  • 9,139
  • 3
  • 37
  • 48
0

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);
}
Community
  • 1
  • 1
Jarno Argillander
  • 5,885
  • 2
  • 31
  • 33