Android ACTION_SENDTO 用于发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3132889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ACTION_SENDTO for sending an email
提问by Sang Shin
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?
在 Android 2.1 中执行以下代码片段时,我遇到“当前不支持此操作”错误情况。片段有什么问题?
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
Uri uri = Uri.parse("mailto:[email protected]");
intent.setData(uri);
intent.putExtra("subject", "my subject");
intent.putExtra("body", "my message");
startActivity(intent);
}
回答by Pierangelo Dal Ben
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.
如果您使用ACTION_SENDTO
,putExtra()
则无法向意图添加主题和文本。使用setData()
该Uri
工具添加主题和文本。
This example works for me:
这个例子对我有用:
// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
"mailto:[email protected]" +
"?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"));
回答by Andy Weinstein
Actually I found a way where the EXTRAs work. This is a combination of an answer I found here regarding ACTION_SENDTO
实际上,我找到了 EXTRA 工作的方法。这是我在此处找到的关于 ACTION_SENDTO 的答案的组合
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
and something for HTML which I found here:
以及我在这里找到的 HTML 内容:
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)
如何发送 HTML 电子邮件(但是在此 HTML 帖子中如何使用 ACTION_SENDTO 的变体对我不起作用 - 我得到了您所看到的“不支持操作”)
// 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="[email protected]";
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..."));
回答by MPG
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
这个对我有用