过滤选择器意图

Filtering chooser intent

我想收到用户的电子邮件。我正在尝试过滤选择器意图,但我在某个时候卡住了。

选择器意图带来用户的联系人。我只想显示已安装的电子邮件应用程序,当然 '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);

改变 MIME 类型就是答案

使用

intent.setType("message/rfc822");

这就是我做的。

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