使用ACTION_SEND直接通过Gmail发送电子邮件,而不是从动作列表中选择

时间:2011-04-27 10:28:49

标签: android email

我已阅读此问题以了解如何使用ACTION_SEND在Android中发送电子邮件:Sending email from android app

但问题是:我想直接使用Gmail发送电子邮件,我不想显示操作列表并再次选择Gmail。

我可以这样做吗?

2 个答案:

答案 0 :(得分:2)

答案 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();
                }


            }
        }