【问题标题】:Android KitKat: Get the filepath of an image from "Recent" sectionAndroid KitKat:从“最近”部分获取图像的文件路径
【发布时间】:2014-05-01 13:55:00
【问题描述】:

从 ACTION_GET_CONTENT 意图中,我可以通过如下光标读取所选文件的文件路径:

String[] projection = { MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(data.getData(), projection, null, null, null);
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
cursor.moveToFirst(); 
capturedImageFilePath = cursor.getString(column_index_data);
cursor.close(); 

这给了我这样一个可用的结果:

/storage/emulated/0/DCIM/Camera/1397538721449.jpg

这在我的所有测试设备上都可以正常工作,甚至在 Android KitKat 设备上,“最近”部分中的文件除外。 captureImageFilePath 在这种情况下为空,如果我尝试读取这样的路径:

Uri myUri = data.getData();
capturedImageFilePath = myUri.getPath();

我得到这样的结果,我不能用它来解码文件:

/document/image:237

如何获得实际的文件路径?这一定是可能的,因为设备上的其他应用程序设法显示正确的文件,但我在谷歌上没有找到任何其他方法。有没有办法把上面的文件号变成实际的文件路径?

我在运行 Android 4.4.2 的 Nexus 7 和 Nexus 10 平板电脑上遇到此问题。

【问题讨论】:

    标签: android android-intent android-4.4-kitkat


    【解决方案1】:

    好的,这成功了:

    Uri selectedImageURI = data.getData();
    InputStream input = getContentResolver().openInputStream(selectedImageURI);
    bmp = BitmapFactory.decodeStream(input);
    

    因为我只需要获取位图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2015-08-16
      • 1970-01-01
      相关资源
      最近更新 更多