I have an intent that can be used to allow the user to select some images in an image app like galley(or any other present in the user's device).
I want the user to select ONLY 10 images but i don't know how i can set this maximum on the intent. i have tried to see if i can use ClipData but clipdata doesn't have methods to set maximum number of items.
ClipboardManager manager = getSystemService(Context.CLIPBOARD_SERVICE)
ClipData clipdata = manager.getPrimaryClip();// in short whether i get
or i create a clipdata, there are no methods to set maximum number of
items to be held into that clip
here is my intent.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
How can i limit the user to select only 10 photos?
using ClipData
check returned item count
ClipData mClipData = data.getClipData();
// here you can check how many images user has selected.
if(mClipData.getItemCount() >= 10) {
// do needful here
Log.e("APP_TAG", "Greater than THRESHOLD.");
// show some error
return;
}
refer this question for more details.
You can try this library : https://github.com/sangcomz/FishBun?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=2785
It allows you to set maximum number of images that can be shared. You can also customize PickerActivity by setting color of actionBar & statusBar. Also can set Your custom message when reached to specified limit.
Hope this will help you.
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