4

I am trying to add multi select image feature in my android app. This is how I am trying to do it

val gallery = Intent( Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI )
gallery.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(gallery, ACTION_REQUEST_GALLERY)

In emulator with OS version 9, 10 it works perfectly fine. But when I test it on Oppo F5 with OS version 7.1.1 then it doesnt work.

But if I add gallery.setAction(Intent.ACTION_GET_CONTENT) then I can select multiple images on all devices but problem is that this method show images in very weird way and its not that much user friendly.

Any help will be highly apprecited, thanks

Zohab Ali
  • 8,426
  • 4
  • 55
  • 63
  • see here also although the answer below is correct for this question : https://stackoverflow.com/a/70828005/3904109 – DragonFire Jan 24 '22 at 01:23

1 Answers1

5

But when I test it on Oppo F5 with OS version 7.1.1 then it doesnt work.

ACTION_PICK is not documented to support EXTRA_ALLOW_MULTIPLE. Specifically:

Hence, you should not assume that any ACTION_PICK activity will do anything in response to your EXTRA_ALLOW_MULTIPLE extra.

this method show images in very weird way and its not that much user friendly.

There are over 26,000 Android device models. There will be hundreds of different pre-installed apps for ACTION_PICK and ACTION_GET_CONTENT that might handle your request. How any of them render their UI, and how any of them react to unexpected extras, is up to their developers, not you or I. You seem to think that ACTION_PICK always results in one form of UI; that is incorrect.

Any help will be highly apprecited, thanks

Either:

  • Use ACTION_PICK and live with fact that EXTRA_ALLOW_MULTIPLE may be ignored, or

  • Use ACTION_GET_CONTENT/ACTION_OPEN_DOCUMENT, or

  • Use the MediaStore APIs directly and render your own image selector, or

  • Use one of the few dozen libraries that implement an image selector

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491