Found the option, suitable for Android >= 22. Maybe it can help somebody.
Starting with Android 22 there's an option to send IntentSender
object in createChooser
method. You can create a pending intent for a broadcast receiver in which you can get the package name of the app on which a user clicked.
Receiver:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
// do something here
}
}
Manifest:
<receiver android:name="MyReceiver" android:exported="false"/>
Creating pending intent:
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
And then using it in the chooser intent:
startActivity(Intent.createChooser(share
, "some_title"
, pendingIntent.getIntentSender()));
Then in onReceiver
you can get the package name of the app:
String selectedAppPackage = String.valueOf(intent.getExtras().get(EXTRA_CHOSEN_COMPONENT))
Source: medium blogpost