我有这样的图像URI:“
content://com.sceburgapp.provider/external_files/.pkgname/file1.jpg
他说:“这是一个很好的选择。”
现在每当我找到路,它就会给我:
/外部文件/.pgname/file1.jpg
他说:“这是一个很好的选择。”
我想从内容URI获取realpaths。
我从StackOverflow获得了解决方案,我尝试了下面的代码,但没有为我工作:
public 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();
}
}
}
有人知道怎么做吗?我用上面的代码时出错了。
java.lang.illegalargumentException:列“_data”不存在。可用列:[]
因为ContentUri使用了文件提供程序,所以它只在nought和oreo设备中工作。