Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 521
Pierre Avatar asked Jan 31 '12 17:01

Pierre


2 Answers

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.

like image 161
CommonsWare Avatar answered Nov 08 '22 03:11

CommonsWare


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);
}
like image 39
Oded Breiner Avatar answered Nov 08 '22 03:11

Oded Breiner