ACTION_SENDTO不起作用

Kar*_*mil 4 email android sendto android-activity

我想从我的应用发送一封电子邮件.所以我使用了以下代码.

String uriText = "abcd@gmail.com" + "?subject=" + URLEncoder.encode("Subject") + "&body=" + URLEncoder.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)

我已经配置了Gmail和电子邮件应用程序.我测试了我的Nexus S(JellyBean)和HTC T-Mobile G2(GingerBread).它们都显示"没有应用可以执行此操作."

有没有人知道这里有什么问题?

Com*_*are 10

如果你要使用ACTION_SENDTO,Uri应该使用mailto:smsto:方案.所以,试试吧mailto:abcd@gmail.com.


ρяσ*_*я K 8

如果您Intent.setData 用于发送电子邮件,请将您的代码更改为:

String uriText = "mailto:someone@example.com" +
                 "?subject=" + URLEncoder.encode("Subject") + 
                 "&body=" + URLEncoder.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)