android Uri获取真实路径转换成File的方法

Uri uri = data.getData();

String[] proj = { MediaStore.Images.Media.DATA };

Cursor actualimagecursor = managedQuery(uri,proj,null,null,null);

int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

actualimagecursor.moveToFirst();

String img_path = actualimagecursor.getString(actual_image_column_index);

File file = new File(img_path);


以下是4.2.2之后,managedQuery方法被废弃后的解决方案:
public String getRealPathFromURI(Uri contentUri) {
    String res = null;
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
    if(cursor.moveToFirst()){;
       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       res = cursor.getString(column_index);
    }
    cursor.close();
    return res;
}

 

 

http://blog.csdn.net/sp6645597/article/details/20215563

android Uri获取真实路径转换成File的方法,布布扣,bubuko.com

android Uri获取真实路径转换成File的方法

上一篇:IOS开发 - Create Push Segue Animation Without UINavigationController


下一篇:APP 抓包-fiddler