Android:Intent.EXTRA_ALLOW_MULTIPLE仅允许一次选择 [英] Android: Intent.EXTRA_ALLOW_MULTIPLE allows only single picking

查看:1377
本文介绍了Android:Intent.EXTRA_ALLOW_MULTIPLE仅允许一次选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用"Intent.EXTRA_ALLOW_MULTIPLE"意图过滤器从Android库中打开多个图像:

I want to open multiple images from the Android gallery using "Intent.EXTRA_ALLOW_MULTIPLE" intent filter:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    startActivityForResult(Intent.createChooser(intent, "Add images"), SELECT_MULTIPLE_IMAGES);
}

但是无论我使用什么应用程序(本机库,QuickPic应用程序),我都只能选择一张图片.该测试设备运行的是Android 5.1.

But whatever app I use (native gallery, QuickPic app), I can only select one single picture. The test device is running Android 5.1.

如何选择多张图像?

推荐答案

当前正在我的一个实时应用程序中工作,该应用程序涵盖使用4.4版及更高版本的Gallary选择图像,以及编写自己的自定义图库的图像.

This is currently working in one of my recent live application which covers selection of images using Gallary for 4.4 and above and below that using writing your own custom gallery.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    try {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_IMAGE_REQUEST_GALLERY);
    }catch(Exception e){
        Intent photoPickerIntent = new Intent(this, XYZ.class);
        startActivityForResult(photoPickerIntent, SELECT_IMAGE_REQUEST);
    }
} else {
    Intent photoPickerIntent = new Intent(this, XYZ.class);
    startActivityForResult(photoPickerIntent, SELECT_IMAGE_REQUEST);
}

这篇关于Android:Intent.EXTRA_ALLOW_MULTIPLE仅允许一次选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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