Android Image Picker Select multiple images from gallery with a maximum limit of 5

和自甴很熟 提交于 2019-12-03 23:26:08

It already keeps track of how many images are selected at the top by default:

On that particular device, perhaps. Please understand that there are thousands of Android device models, and manufacturers set up their own UI to replace that of stock apps. Do not assume that all devices will show a count in the action bar.

Is there a way to set a maximum limit? Like to have a user only be able to select up to 5 images.

Not via ACTION_PICK. ACTION_PICK is not documented to support EXTRA_ALLOW_MULTIPLE at all, and so there may be devices that do not allow for multiple selection for that Intent. Even on the Intent actions for which EXTRA_ALLOW_MULTIPLE is part of the protocol (e.g., ACTION_GET_CONTENT), there are no extras for controlling the maximum count.

You are welcome to create your own image-selection UI, based on the results of querying MediaStore, and establish your own limits. There are also several image picker libraries, and one of those may already offer this feature.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!