33

I am experiecing "This action is not currrently supported" error condition when execute the following code snippet in Android 2.1. What is wrong with the snippet?

public void onClick(View v) {
  Intent intent = new Intent(Intent.ACTION_SENDTO);
  Uri uri = Uri.parse("mailto:myemail@gmail.com");
  intent.setData(uri);
  intent.putExtra("subject", "my subject");
  intent.putExtra("body", "my message");
  startActivity(intent);
}
Jonik
  • 80,077
  • 70
  • 264
  • 372
Sang Shin
  • 361
  • 1
  • 3
  • 6

3 Answers3

94

If you use ACTION_SENDTO, putExtra() does not work to add subject and text to the intent. Use setData() and the Uri tool add subject and text.

This example works for me:

// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
    "mailto:youremail@gmail.com" + 
    "?subject=" + Uri.encode("some subject text here") + 
    "&body=" + Uri.encode("some text here");

Uri uri = Uri.parse(uriText);

Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email")); 
Teo Inke
  • 5,928
  • 4
  • 38
  • 37
  • 1
    Should you really be using `URLEncoder`? Wouldn't that make `' '` (space) into `'+'` and not `"%20"`? – dacwe Sep 29 '12 at 22:03
  • This was my favourite... But I have just come across a situation where an e-mail client replaces all plus signs by a single space character, so I'm now leaving this path. I would assume that the mail app does its decoding one time too often or such... frankly, I don't want to know... it's simply annoying. – class stacker Jan 29 '13 at 13:13
  • ...so, no matter what, E-Mail V3.0 will turn all + signs into whitespace if you pass the body via an URI; I can't believe it. – class stacker Jan 29 '13 at 14:27
  • 1
    `Uri.parse(...)` seems to do the encoding for you, so in fact there's no need for the `URLEncoder` (or that's what I found). It also works for +. – Andrew Wyld Dec 10 '13 at 15:53
19

Actually I found a way where the EXTRAs work. This is a combination of an answer I found here regarding ACTION_SENDTO

http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when

and something for HTML which I found here:

How to send HTML email (but the variant of how to use ACTION_SENDTO in this HTML post didn't work for me - I got the "action not supported" which you are seeing)

    // works with blank mailId - user will have to fill in To: field
    String mailId="";
    // or can work with pre-filled-in To: field
// String mailId="yourmail@gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, 
                                    Uri.fromParts("mailto",mailId, null)); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here"); 
    // you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here"); 
    // or get fancy with HTML like this
emailIntent.putExtra(
             Intent.EXTRA_TEXT,
             Html.fromHtml(new StringBuilder()
                 .append("<p><b>Some Content</b></p>")
                 .append("<a>http://www.google.com</a>")
                 .append("<small><p>More content</p></small>")
                 .toString())
             );
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Community
  • 1
  • 1
Andy Weinstein
  • 2,639
  • 3
  • 21
  • 32
  • 1
    I have seen that solution, but it's not really the case that it builds a standard conformant HTML mail; it's more that many mail clients will try to be extra smart and display it nevertheless -- after all, there are so many non standard conformant e-mails being sent daily that you couldn't count them. Besides, this combination of _ACTION_SENDTO_ and _EXTRA_TEXT_ is **not supported by all mail clients**, e.g. K-9 before 4.2 would just ignore the extras. – class stacker Jan 29 '13 at 14:02
  • Excellent, thanks. Turns out this is what broke HTML sending for me: `emailIntent.setType("text/html");` Removed that and it works fine. – Jonik Jan 17 '14 at 22:28
6

You Can Try This One

 Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto", emailID, null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT,
            Subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT,
            Text);
    startActivity(Intent.createChooser(emailIntent, Choosertitle);

It Works For me

Angel Koh
  • 12,479
  • 7
  • 64
  • 91
MPG
  • 785
  • 6
  • 20