ACTION_SENDTO for sending an email

2019-01-04 01:57发布

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

3条回答
The star\"
2楼-- · 2019-01-04 02:41

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

查看更多
Lonely孤独者°
3楼-- · 2019-01-04 02:46

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..."));
查看更多
来,给爷笑一个
4楼-- · 2019-01-04 02:53

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")); 
查看更多
登录 后发表回答