我有一个代码,用于发送电子邮件
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { to });
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, msg);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Start.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
但是,当这个意图被触发时,我会在列表中看到许多项目,例如 sms 应用程序、gmail 应用程序、facebook 应用程序等。
我如何过滤它并仅启用 Gmail 应用程序(或者仅启用电子邮件应用程序)?
Use android.content.Intent.ACTION_SENDTO
(new Intent(Intent.ACTION_SENDTO);
)仅获取电子邮件客户端列表,没有 Facebook 或其他应用程序。只是电子邮件客户端。
我不建议您直接进入电子邮件应用程序。让用户选择他最喜欢的电子邮件应用程序。别约束他。
如果您使用 ACTION_SENDTO,则 putExtra 无法将主题和文本添加到意图。使用 Uri 添加主题和正文。
Example
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("[email protected]") +
"?subject=" + Uri.encode("the subject") +
"&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)