更新时间:2023-12-02 16:01:22
您可以使用更换context.getContentResolver()查询
和 LoaderManager
(你需要使用兼容包之前API版本11支持的设备)。
You could replace it with context.getContentResolver().query
and LoaderManager
(you'll need to use the compatibility package to support devices before API version 11).
不过,它看起来像你只使用查询一次:你可能甚至不需要说。也许这会工作?
However, it looks like you're only using the query one time: you probably don't even need that. Maybe this would work?
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;
}