San*_*hin 31 email android android-intent
我在Android 2.1中执行以下代码片段时遇到"此操作不受支持"错误情况.这个片段有什么问题?
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);
}
Run Code Online (Sandbox Code Playgroud)
小智 82
如果您使用ACTION_SENDTO,putExtra()则无法向主题添加主题和文本.使用setData()和Uri工具添加主题和文本.
这个例子对我有用:
// 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"));
Run Code Online (Sandbox Code Playgroud)
And*_*ein 19
实际上我找到了EXTRAs工作的方式.这是我在这里找到关于ACTION_SENDTO的答案的组合
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
和我在这里找到的HTML的东西:
如何发送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="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..."));
Run Code Online (Sandbox Code Playgroud)
你可以试试这个
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);
Run Code Online (Sandbox Code Playgroud)
这个对我有用