如何将内容转换://乌里到实际的文件路径? [英] How to convert content:// Uri into actual file path?

查看:124
本文介绍了如何将内容转换://乌里到实际的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能SD卡,其中一个内容上的实际文件路径:// URI是指向一个图像

how can I get the actual file path on the SD card where a content:// uri is pointing for an image?

推荐答案

我已经适应了code的@ hooked82挂钩:

I've adapted the code which @hooked82 linked to:

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;
}

这篇关于如何将内容转换://乌里到实际的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆