如何将content:// Uri转换为实际的文件路径?

hun*_*erp 9 android

如何在SD卡上获取内容:// uri指向图像的实际文件路径?

Jon*_*man 13

我已经调整了@ hooked82链接到的代码:

protected String convertMediaUriToPath(Uri uri) {
    String [] proj={MediaStore.Images.Media.DATA};
    Cursor cursor = getContentResolver().query(uri, proj,  null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index); 
    cursor.close();
    return path;
}
Run Code Online (Sandbox Code Playgroud)

  • 我发现在nexus 5的默认文件选择器上执行此操作不起作用 (4认同)