Get the list of apps capable of handling the SEND intent to display in a View (not a popup dialog)

六月ゝ 毕业季﹏ 提交于 2019-12-02 18:12:08

Call queryIntentActivities() on PackageManager, given an ACTION_SEND Intent configured as you would use with createChooser() (i.e., has the MIME type, Uri, etc.). This will give you a list of all the matches that would appear in the chooser. You can then make use of the user's selection to launch the actual activity.

Here is a sample project that uses this to create a home screen-style launcher.

List<String> packages = new ArrayList<>();

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "test");
sendIntent.setType("text/plain");
List<ResolveInfo> resolveInfoList = getPackageManager()
    .queryIntentActivities(sendIntent, 0);

for (ResolveInfo resolveInfo : resolveInfoList) {
    packages.add(resolveInfo.activityInfo.packageName);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!