我想收到用户的电子邮件。我试图过滤选择器的意图,但我在某些时候陷入困境。
选择器意图带来用户的联系人。我只想显示已安装的电子邮件应用,其中包含'到'现场自动填充。
如何删除用户的联系人并仅显示电子邮件应用程序?
任何帮助将不胜感激。
到目前为止,这是我的代码:
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);
答案 0 :(得分:0)
更改MIME类型是答案
使用
intent.setType("message/rfc822");
答案 1 :(得分: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);