简体   繁体   English

使用android中的MultipleImageSelect库从图库中获取选定图像的路径

[英]get path of selected images from gallery using MultipleImageSelect library in android

In my project i need a way of get the path of several images selecteds from the gallery. 在我的项目中,我需要一种方法来获取从画廊中选择的几幅图像的路径。 I´m using this library MultipleSelectImages 我正在使用这个库MultipleSelectImages

It´s apparently work fine, but in the onActivityResult i need the array with the path of each image, however the result I get is this: 它显然工作正常,但是在onActivityResult中,我需要带有每个图像路径的数组,但是我得到的结果是这样的:

Paths: [com.darsh.multipleimageselect.models.Image@1e6d3057, com.darsh.multipleimageselect.models.Image@33824744]

...when i need the real path (/storage/emulated/0/DCIM/Camera/20150426_110936.jpg) ...当我需要真实路径时(/storage/emulated/0/DCIM/Camera/20150426_110936.jpg)

Reading the doc of the library don´t found solution. 阅读该库的文档未找到解决方案。

This is the onActivityResult method: 这是onActivityResult方法:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
        //The array list has the image paths of the selected images
        ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);

        Log.i("myLogs", "Paths:" + " " + images);
    }
}

...Where "image" it´s imported from the library ...从库中导入“图像”的位置

import com.darsh.multipleimageselect.models.Image;

I´m not using EXTRA_ALLOW_MULTIPLE because need that the app works in android api 16 version 我没有使用EXTRA_ALLOW_MULTIPLE,因为需要该应用程序可以在android api 16版本中运行

Thanks in advanced. 提前致谢。

Try to use below code; 尝试使用下面的代码;

onActivityResult();- onActivityResult();-

            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };


            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);

            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String imgPath = cursor.getString(columnIndex);
            cursor.close();

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

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