从图库中选择多个图像 [英] Pick multiple images from gallery

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

问题描述

当我从图库中选择多个图像时,如何读取/检索路径或Uri[]?

How to read/retrieve paths or Uri[] when I select multiple images from gallery?

我想称呼它

Uri[] originalUri = data.getData();

但是实际上,我只得到了一个,只获取了一个Uri:

But in reality I'm getting this only, fetching only one Uri:

 Uri originalUri = data.getData();

推荐答案

@RIT,正如您所说,您希望在andorid kitkat中获得多个图像.

@RIT as said by you that you want to get multiples images in andorid kitkat .

我尝试使用下面的代码为Xperia M2 4.4.4工作.

I have try below code which work for me for Xperia M2 4.4.4

用于开始图像选择活动

private void startImageSelection(){

        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"), PICK_IMAGES);
    } 

但是用户需要长按选择图像

But user need to select images by long press

现在可以读取选定的图片Uri,将以下代码用于onActivityResult

Now to read selected images Uri use below code for onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub

        if(requestCode==PICK_IMAGES){

            if(resultCode==RESULT_OK){
                //data.getParcelableArrayExtra(name);
                //If Single image selected then it will fetch from Gallery
                if(data.getData()!=null){

                    Uri mImageUri=data.getData();

                }else{
                    if(data.getClipData()!=null){
                        ClipData mClipData=data.getClipData();
                        ArrayList<Uri> mArrayUri=new ArrayList<Uri>();
                        for(int i=0;i<mClipData.getItemCount();i++){

                            ClipData.Item item = mClipData.getItemAt(i);
                            Uri uri = item.getUri();
                            mArrayUri.add(uri);

                        }
                        Log.v("LOG_TAG", "Selected Images"+ mArrayUri.size());
                    }

                }

            }

        }

        super.onActivityResult(requestCode, resultCode, data);
    }

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

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