使用这个问题的答案,您可以获得所有有意图的应用程序的列表android.content.Intent.ACTION_SEND
这是我在下面编码的一个工作示例(最终在我的设备上选择了 gmail)
**公平警告 - 如果未设置电子邮件帐户,将抛出 NullPointerException 您应该对变量添加空检查pkgAppsList
并告诉用户未找到或已设置电子邮件应用程序
//set the main intent to ACTION_SEND for looking for applications that share information
Intent intent = new Intent(Intent.ACTION_SEND, null);
//intent.addCategory(Intent.CATEGORY_LAUNCHER); //if you want extra filters
//filter out apps that are able to send plain text
intent.setType("plain/text");
//get a list of apps that meet your criteria above
List<ResolveInfo> pkgAppsList = this.getPackageManager().queryIntentActivities( intent, PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_RESOLVED_FILTER);
//select the first one in the list
ResolveInfo info = pkgAppsList.get(0);
String packageName = info.activityInfo.packageName;
String className = info.activityInfo.name;
//set the intent to luanch that specific app
intent.setClassName(packageName, className);
//some samples on adding more then one email address
String aEmailList[] = { "user@fakehost.com","user2@fakehost.com" };
String aEmailCCList[] = { "user3@fakehost.com","user4@fakehost.com"};
String aEmailBCCList[] = { "user5@fakehost.com" };
//all the extras that will be passed to the email app
intent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
intent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
intent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "My message body.");
//start the app
startActivity(intent);
如果您想将正在调用的应用列入白名单,您可以遍历列表,检查特定包的每个包名称(例如:gmail 是“com.google.android.gm”)