0

I want to create a dialog which would let users to select either camera or gallery to pick an image from. Each item in the dialog needs an icon and an image. How can I get those for the default camera and gallery?

Update

I'm currently getting it like this

val galleryIntent = Intent(Intent.ACTION_GET_CONTENT).apply {
    setType("image/*")
    addCategory(Intent.CATEGORY_OPENABLE)
    putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/jpeg", "image/png"))
}
val galleryResInfo = packageManager.queryIntentActivities(galleryIntent, 0)[0]

Then in the dialog recycler view holder I can get the icon and name like this

val packageManager = holder.appName.context.packageManager
holder.appIcon.setImageDrawable(app.resolveInfo.loadIcon(packageManager))
holder.appName.setText(app.resolveInfo.loadLabel(packageManager))

Aren't there a better solution?

yaugenka
  • 2,602
  • 2
  • 22
  • 41
  • as you were not happy with the two answers it is unclear what you want to achieve. If you want to launch the Camera or the Gallery with two buttons, you can provide your own two icons for that and use the intents from the answers. If you need the Applications itself, you can also go with that answer: https://stackoverflow.com/a/23172341/1505074 – Christian Jan 08 '20 at 09:31
  • packageManager.resolveActivity from the answer at that link was exactly what I was looking for. The only thing which is missing from there is the MATCH_DEFAULT_ONLY flag which insures to return the same activity as startActivity would. Thank you, Christian! – yaugenka Jan 08 '20 at 10:22

2 Answers2

0

If you are starting the two intents

Intent(MediaStore.ACTION_IMAGE_CAPTURE)
Intent(Intent.ACTION_GET_CONTENT) 

with the corresponding parameters separately but without a chooser, Android will open the default App for that if any is selected.

Christian
  • 4,596
  • 1
  • 26
  • 33
0

Gallery Intent

Intent intent =new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

Camera Intent

Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50