ACTION_SENDTO 用于发送电子邮件

问题描述:

我在 Android 2.1 中执行以下代码片段时遇到当前不支持此操作"错误情况.这段代码有什么问题?

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

如果您使用 ACTION_SENDTOputExtra() 无法向意图添加主题和文本.使用 setData()Uri 工具添加主题和文本.

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