Code:
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.addCategory(Intent.CATEGORY_HOME);
Intent chooser = Intent.createChooser(launchIntent, "Complete Action using..");
activity.startActivity(chooser);
I don't see any way to tell which Intent (HOME category launcher) was selected. There is no Inent.addOnActionSetListener, and no chooser.addOnIntentChosenListener etc. So how can I tell which was selected? Do Or do I have to write my own chooser for this?
The answer provided by BinHe works but the problem is that a big number of apps is shown. In this solution I use the Intent.ACTION_PICK_ACTIVITY but only the apps compatible with Intent.ACTION_SEND will be shown, and you will know which option the user selected.
Finally, to be able to get the app selected by the user you must override the onActivityResult on your activity:
On Android 5.1+, you can use the three-parameter edition of the
createChooser()
method, where the last parameter is anIntentSender
that you can use to find out what was chosen.Prior to Android 5.1, there is nothing in Android to let you know what the user chose.
I did in different way, no need to implement custom component:
Send Intent:
Add BroadcastReceiver
ApplicationSelectorReceiver.class
in manifest.ApplicationSelectorReceiver.java
Result:
Hope this would help others.
This should work for early versions of Android.
Use intent PICKER instead of CHOOSER. The difference is that picker won't start the target intent automatically, but rather, it returns to onActivityResult() the target intent with the selected app's component name attached. Then you start the target intent in the callback as a 2nd step.
A little bit of code should explain,