在在奇巧的新画廊访问我得到了我的SD卡中的真实路径用这种方法
Before new gallery access in KitKat I got my real path in sdcard with this method
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
startManagingCursor(cursor);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
现在,该Intent.ACTION_GET_CONTENT返回不同的数据:
Now, the Intent.ACTION_GET_CONTENT return different data:
在
content://media/external/images/media/62
现在:
content://com.android.providers.media.documents/document/image:62
我怎么能管理,以获得SD卡的实际路径?
How could I manage to obtain the real path in sdcard?
注意:这个答案的地址问题的一部分。对于一个完整的解决方案(在库的形式),看看用户保罗·伯克
回答以下。
Note: This answer addresses part of the problem. For a complete solution (in the form of a library), look at user Paul Burke's
answer below.
您可以使用URI来获得文件ID
,然后查询或者 MediaStore.Images.Media.EXTERNAL_CONTENT_URI
或 MediaStore.Images.Media.INTERNAL_CONTENT_URI
(视SD卡的情况)。
You could use the Uri to obtain document id
, and then query either MediaStore.Images.Media.EXTERNAL_CONTENT_URI
or MediaStore.Images.Media.INTERNAL_CONTENT_URI
(depending on the SD card situation).
要获取文档ID:
// Will return "image:x*"
String wholeID = DocumentsContract.getDocumentId(uriThatYouCurrentlyHave);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = { MediaStore.Images.Media.DATA };
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getContentResolver().
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{ id }, null);
String filePath = "";
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
参考:我没能找到这个解决方案是从岗位。我想问问楼主在这里作出贡献。会看一些在今晚。
Reference: I'm not able to find the post that this solution is taken from. I wanted to ask the original poster to contribute here. Will look some more tonight.