我想收到用户的电子邮件。我正在尝试过滤选择器意图,但我被困在某个点上。
选择者意图带来用户的联系人。我只想显示已安装的电子邮件应用程序,当然会自动填充“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);