I'm using implicit intent to, say, open Gallery to pick an image. I'm normally doing the following:
Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
.takeIf { it.resolveActivity(activity.packageManager) != null }
?.let {
val intent = Intent.createChooser(it, "Choose gallery")
activity.startActivityForResult(intent, rc)
}
But if that intent is resolved by just single application on my device, and there is no other gallery app but one, then chooser will only display single choice which is useless.
How could I figure out whether there are many activities that could handle that intent? How to get the number of activities that actually fit? And hence, decide whether to show chooser or not.
How could I figure out whether there are many activities that could handle that intent?
Call queryIntentActivities() on a PackageManager, supplying your Intent.
How to get the number of activities that actually fit?
Sorry, but I do not know what "fit" means in this context.
And hence, decide whether to show chooser or not
You could simply get rid of the Intent.createChooser() call. You only use that when you wish to force the user to have to deal with a chooser. If you leave Intent.createChooser() off, the system will show a chooser on its own when needed. That occurs if:
Intent, andIntent structureBTW, please remove type = "image/*" from your code. ACTION_PICK does not use a MIME type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With