【问题标题】:get path of selected images from gallery using MultipleImageSelect library in android使用 android 中的 MultipleImageSelect 库从图库中获取所选图像的路径
【发布时间】:2015-12-19 12:16:16
【问题描述】:

在我的项目中,我需要一种方法来获取从图库中选择的多个图像的路径。 我正在使用这个库MultipleSelectImages

它显然工作正常,但在 onActivityResult 我需要包含每个图像路径的数组,但是我得到的结果是这样的:

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

...当我需要真实路径时(/storage/emulated/0/DCIM/Camera/20150426_110936.jpg)

阅读图书馆的文档没有找到解决方案。

这是 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);
    }
}

...从库中导入“图像”的位置

import com.darsh.multipleimageselect.models.Image;

我没有使用 EXTRA_ALLOW_MULTIPLE,因为需要该应用在 android api 16 版本中运行

提前致谢。

【问题讨论】:

    标签: android path gallery


    【解决方案1】:

    尝试使用下面的代码;

    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();
    

    【讨论】:

    • data.getData() = null :/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多