android中转换content://media/external/images/media/539163为/storage/emulated/0/DCIM/Camera/IMG_20160807_

在上传照片时遇到上传路径异常:content://media/external/images/media/539163
转成:/storage/emulated/0/DCIM/Camera/IMG_20160807_133403.jpg路径;


PHOTO_DATA(content://media/external/images/media/539163)

Log.d(“log”,”照片路径信息:”+String.valueOf(getRealPathFromUri(this,PHOTO_DATA)));


解决方法:
public static String getRealPathFromUri(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}

你可能感兴趣的:(Android,android)