简体   繁体   English

Android Studio-从(常规)图库中选择多张图片

[英]Android Studio - Select multiple pictures from (normal) gallery

I want a user to be able to select multiple images from the 'normal' gallery. 我希望用户能够从“正常”图库中选择多个图像。 It currently opens a sort of file explorer instead of the gallery. 当前,它打开一种文件浏览器而不是图库。 Is there anything I can do so it uses the 'normal' gallery? 我有什么办法可以使用“正常”画廊?

I currently open the file explorer/gallery the following way: 我目前通过以下方式打开文件资源管理器/图库:

    Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    gallery.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    gallery.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(gallery, "Select Picture"), 5);

Try to filter the results for image type. 尝试过滤图像类型的结果。 Something like this: 像这样:

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG);

Adding this would probably be enough for your code: 添加此代码可能足以满足您的代码要求:

gallery.setType("image/*");

I want a user to be able to select multiple images from the 'normal' gallery 我希望用户能够从“正常”图库中选择多张图片

There are over 20,000 Android device models. 有超过20,000种Android设备型号。 There will be dozens, if not hundreds, of pre-installed gallery apps, in addition to those that users install. 除了用户安装的应用程序之外,还将有数十种(如果不是数百种)预安装的图库应用程序。 There is no "normal". 没有“正常”。

There is also no requirement for any of those gallery apps to support multiple selection. 也不需要任何这些图库应用程序支持多种选择。

It currently opens a sort of file explorer instead of the gallery. 当前,它打开一种文件浏览器而不是图库。

My guess is that you are referring to the UI brought up by ACTION_GET_CONTENT . 我的猜测是您指的是ACTION_GET_CONTENT带来的UI。

Is there anything I can do so it uses the 'normal' gallery? 我有什么办法可以使用“正常”画廊?

Remove the ACTION_GET_CONTENT line, so that your Intent action is ACTION_PICK . 删除ACTION_GET_CONTENT行,以使您的Intent操作为ACTION_PICK

Bear in mind that since ACTION_PICK is not documented to support EXTRA_ALLOW_MULTIPLE — and since support for extras is always optional — very few devices are likely to return multiple images to you. 请记住,由于未记录ACTION_PICK来支持EXTRA_ALLOW_MULTIPLE ,并且由于对Extras的支持始终是可选的,因此很少有设备会向您返回多张图像。

Also bear in mind that ACTION_PICK is not guaranteed to display something that you might consider to be a gallery app. 另外请记住,不能保证ACTION_PICK显示您认为是图库应用的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM