Android Image Picker从图库中选择多个图像,最大限制为5个 [英] Android Image Picker Select multiple images from gallery with a maximum limit of 5

查看:1250
本文介绍了Android Image Picker从图库中选择多个图像,最大限制为5个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户需要能够选择多张图片以将它们发送到某个地方.但是,它们一次只能发送五张图像.我需要能够限制它们可以通过图像选择器"从图库中拾取的图像数量.

I have an app where the user needs to be able to choose multiple pictures to send them somewhere. However, they can only send five images at a time. I need to be able to limit the number of images that they can pick from the gallery through the Image Picker.

一句话:我想限制用户可以从图库的默认图像选择器中选择的图像/照片的数量.

这是我用于图片选择器的代码:

Here is the code that I am using for my image picker:

Intent chooseIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
chooseIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(chooseIntent, 2);

它已经可以跟踪默认情况下在顶部选择了多少张图像:

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

是否可以设置最大限制?就像一个用户只能选择最多5张图片.

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

推荐答案

它已经可以跟踪默认情况下在顶部选择了多少张图像:

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

也许在该特定设备上.请理解,有成千上万的Android设备型号,制造商设置了自己的UI来替换库存应用程序的UI.不要以为所有设备都会在操作栏中显示计数.

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.

是否可以设置最大限制?就像一个用户只能选择最多5张图片.

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

不通过ACTION_PICK.记录ACTION_PICK根本不支持EXTRA_ALLOW_MULTIPLE,因此可能有些设备不允许对该Intent进行多重选择.即使对于Intent是协议一部分的Intent操作(例如ACTION_GET_CONTENT),也没有用于控制最大计数的其他功能.

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.

欢迎您根据查询MediaStore的结果创建自己的图像选择UI,并建立自己的限制.还有几个图像选择器库,其中一个可能已经提供了此功能.

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.

这篇关于Android Image Picker从图库中选择多个图像,最大限制为5个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆