相关文章:Android手机读取相册图片,根据URI获取图片路径
从图库获取的Uri:content://media/external/images/media/20782
Uri uri = data.getData();
获取图片的本地路径:/storage/emulated/0/DCIM/Camera/IMG_20181106_142017.jpg
获取方法,将上述的URI传入:
path = getRealFilePath(HnUiUtils.getContext(), uri); //拿到图片
public static String getRealFilePath(final Context context, final Uri uri) {
if (null == uri)
return null;
final String scheme = uri.getScheme();
String data = null;
if (scheme == null)
data = uri.getPath();
else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
data = uri.getPath();
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
Cursor cursor = co