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

本小妞迷上赌 提交于 2019-12-03 04:44:36

问题


I'm trying to get the list of all apps installed on a phone capable of handling the SEND intent. I am currently handling this situation by using Intent.createChooser but this is not what I am trying to achieve as I would like to be able to get access to the list of apps to display them in a View in my activity, in a way similar to how the Android stock Gallery app displays them and NOT in a spinner dialog.

Screenshot available here: http://i.stack.imgur.com/0dQmo.jpg

Any help would be greatly appreciated.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/9083826/get-the-list-of-apps-capable-of-handling-the-send-intent-to-display-in-a-view-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!