我在 Android 2.1 中执行以下代码 fragment 时遇到“当前不支持此操作”错误情况。代码段有什么问题?
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);
}
最佳答案
如果您使用 ACTION_SENDTO
,putExtra()
无法将主题和文本添加到 Intent 。使用 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"));
关于android - ACTION_SENDTO 用于发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3132889/