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

问题描述 投票:0回答:2

我看这个问题知道如何使用ACTION_SEND Android中发送电子邮件:Sending email from android app

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

我可以做吗?

android email
2个回答

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


            }
        }
© www.soinside.com 2019 - 2024. All rights reserved.