Android:Intent.EXTRA_ALLOW_MULTIPLE只允许单一选择

Hyn*_*rix 11 android image-gallery android-intent

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

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);
}
Run Code Online (Sandbox Code Playgroud)

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

如何选择多张图片?

str*_*ike 11

目前我正在使用我最近的一个实时应用程序,其中包括使用Gallary 4.4及以上版本选择图像,使用自己编写的自定义图库.

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);
}
Run Code Online (Sandbox Code Playgroud)

  • 它需要长按才能激活多选模式 (3认同)