Home > Software engineering >  How to set maximum Image selection limit while pickup image from Gallery in Jetpack compose
How to set maximum Image selection limit while pickup image from Gallery in Jetpack compose

Time:08-24

I have implemented multiple image selections from the gallery. However, I want to limit the user to select max 5 images from the gallery.

  TextButton(onClick = {
            scope.launch {
                uploadImageLauncher.launch("image/*")
            }
        }

CodePudding user response:

You have not specified what launcher is.

If you use the new PickMultipleVisualMedia launcher, you can specify maxItems to attempt to limit the number of selections. However, that request will not be honored on all devices, and you will need to check your results to see how many items you get back.

CodePudding user response:

Unfortunately, applying limit to gallery images selection is not possible via inbuild methods. You have to apply some condition is your code, like below:

if(imagesArraylist.size() == 10) {
      Log.e("Show pop-up OR toast msg ", "that you have exceeded selection limit");
} else {
// do something relevant to handle else condition
}

Assuming imagesArraylist is where you are adding the images URI which are selected from gallery.

  • Related