android - 在没有选择器的情况下使用标准 gmail 应用程序发送电子邮件

标签 android android-intent sendmail

我正在尝试使用标准 Gmail 应用程序从我的应用程序发送电子邮件。 但我总是有选择的余地。 如何在没有选择器的情况下立即打开标准 gmail 应用程序? 我不需要任何可以发送电子邮件的应用程序的选择器。 我只需要 GMAIL。 谢谢! 这是我的代码。

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
intent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"mymail@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT   , "Text");
try {
    startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

最佳答案

你能试试这段代码吗?

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.setType("plain/text");
    emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"someone@gmail.com"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Yo");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi");
    startActivity(emailIntent);

关于android - 在没有选择器的情况下使用标准 gmail 应用程序发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30314321/

相关文章:

android - 如何在 Android 自定义数据绑定(bind)中传递带参数的函数

java - 在两个正在运行的 Activity 之间传递数据

android - 亚马逊 Kindle 设备的 map 导航 Intent

email - sSMTP 重写电子邮件中的 "From"字段

Android - 我如何*在*进程加载后执行代码

android - 如何在firebase数据库中获取所有 child 的数据?

android - 这是 Activity 启动模式、 list 或 Intent 标志的更好方法

unix - 如何监控来自 Unix 和 Sendmail 的外发电子邮件?

linux - 如何通过 shell 脚本发送带有投票按钮的电子邮件?

android - 我可以通过在 Android Activity 中声明适当的成员 "static"来获得一些效率吗