使用标准 Gmail 应用程序发送电子邮件,无需选择器

2024-03-24

我正在尝试使用标准 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[]{"[email protected] /cdn-cgi/l/email-protection"});
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[]{"[email protected] /cdn-cgi/l/email-protection"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Yo");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi");
    startActivity(emailIntent);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用标准 Gmail 应用程序发送电子邮件,无需选择器 的相关文章

随机推荐