当前位置:   article > 正文

android中转换content://media/external/images/media/539163为/storage/emulated/0/DCIM/Camera/IMG_20160807__android 把相册地址转为conten地址

android 把相册地址转为conten地址

在上传照片时遇到上传路径异常: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();
}
}
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/254936
推荐阅读
相关标签
  

闽ICP备14008679号