15

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: https://i.stack.imgur.com/0dQmo.jpg

Any help would be greatly appreciated.

Pierre
  • 153
  • 1
  • 4

2 Answers2

20

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    @CommonsWare is there a way to get specific action (in my case ACTION_SEND) from an Application and do something like putExtra("myMessage", shareMessage); so that the Share Action of that gets populated with my shareMessage. I could accomplish till getting the Application which can handle ACTION_SEND. Thank You – Archie.bpgc Oct 01 '12 at 09:09
  • @Archie.bpgc: With regards to extras, see the documentation for `ACTION_SEND` for what is available and *possibly* supported. Each app with an activity that can respond to `ACTION_SEND` has its choice as to whether or not it will support any given extra. And since applications don't have actions -- activities do -- I do not understand the first part of your comment. – CommonsWare Oct 01 '12 at 13:45
  • yeah, i mean Activity there, not Application. Thanks for the reply :) – Archie.bpgc Oct 01 '12 at 13:48
  • Your source code actually helped alot. But it doesnt work exactlty like android's activity chooser dialog. –  Sep 12 '19 at 03:30
  • Actually I think your code does something wrong. You created an intent. Then use package manager to query activities for the intent. Then when you get component name; you create a totally new intent and try to launch it. What I did was modify the original intent with the newly got component name. Then launch it. Everything seems to be working accurately now. THANK YOU!! –  Sep 12 '19 at 04:58
  • @JaveneCPPMcGowan: So long as the `Intent` has the correct data in it, it does not matter how you create the `Intent`. – CommonsWare Sep 12 '19 at 10:44
  • @CommonsWare that is where I think you are wrong. For instance, my app only handles intent if it's action is ACTION_VIEW. Another app, I assume, might handle data differently based on the required action. –  Sep 12 '19 at 22:30
9
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);
}
Oded Breiner
  • 28,523
  • 10
  • 105
  • 71