我已阅读此问题以了解如何使用ACTION_SEND在Android中发送电子邮件:Sending email from android app
但问题是:我想直接使用Gmail发送电子邮件,我不想显示操作列表并再次选择Gmail。
我可以这样做吗?
答案 0 :(得分:2)
How to open Gmail Compose when a button is clicked in Android App?养蜂人的第二个答案。也是具有相同答案的how to direct open Gmail mail composer in android?的副本。
答案 1 :(得分:0)
尝试一下:
final Intent intent = new Intent (android.content.Intent.ACTION_SEND);
intent.setType ("text/plain");
List<ResolveInfo> resInfo = getPackageManager ().queryIntentActivities (intent, 0);
if (!resInfo.isEmpty ()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase ().contains ("android.gm") || info.activityInfo.name.toLowerCase ().contains ("android.gm")) {
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, TextKonnex);
intent.putExtra(android.content.Intent.EXTRA_TEXT, message);
intent.setPackage (info.activityInfo.packageName);
try {
startActivity (android.content.Intent.createChooser (intent,"Sending..."));
Toast.makeText(Main4Activity.this, "Sending an email to your friend! ", Toast.LENGTH_LONG).show();
} catch (ActivityNotFoundException e) {
Toast.makeText(Main4Activity.this, "Error! Try whith other email address! ", Toast.LENGTH_LONG).show();
}
}
}