0

我想收到用户的电子邮件。我正在尝试过滤选择器意图,但我被困在某个点上。

选择者意图带来用户的联系人。我只想显示已安装的电子邮件应用程序,当然会自动填充“to”字段。

如何删除用户的联系人并仅显示电子邮件应用程序?

任何帮助将不胜感激。

到目前为止,这是我的代码:

    List<Intent> emailAppLauncherIntents = new ArrayList<>();

    Intent emailAppIntent = new Intent(Intent.ACTION_SENDTO);
    emailAppIntent.setData(Uri.parse("mailto:test@mail.com"));
    emailAppIntent.putExtra(Intent.EXTRA_EMAIL, "");
    emailAppIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback on "+getContext().getPackageName());
    emailAppIntent.putExtra(Intent.EXTRA_TEXT, mailBody);

    PackageManager packageManager = getActivity().getPackageManager();

    List<ResolveInfo> emailApps = packageManager.queryIntentActivities(emailAppIntent, PackageManager.MATCH_ALL);

    for (ResolveInfo resolveInfo : emailApps) {
        String packageName = resolveInfo.activityInfo.packageName;
        Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
        emailAppLauncherIntents.add(launchIntent);
    }

    Intent chooserIntent = Intent.createChooser(new Intent(), "Select email app:");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, emailAppLauncherIntents.toArray(new Parcelable[emailAppLauncherIntents.size()]));
    startActivity(chooserIntent);
4

2 回答 2

0

这就是我做到的。

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.parse("mailto:"
            + "xyz@abc.com"
            + "?subject=" + "Feedback" + "&body=" + "");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Feedback";
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "xyz@abc.com" });
    intent.putExtra(Intent.EXTRA_TEXT, mailBody);
    intent.setData(data);
    startActivity(intent);
于 2017-06-09T08:58:40.680 回答
0

更改 MIME 类型就是答案

利用

intent.setType("message/rfc822");
于 2017-06-09T01:46:41.227 回答