在做项目的时候,需要调取手机本地的图片并上传到服务器,在小米手机上测试的时候,获取的cursor为null,在其他手机上是没有问题,查询资料发现,在Android4.4之后返回的不再是图片的绝对路径,而是图片的编码,我们需要做一些转换处理才能使用
老子是有素质的人
public static Uri geturi(Intent intent,Context context) {
Uri uri = intent.getData();
String type = intent.getType();
if (uri.getScheme().equals("file") && (type.contains("image/"))) {
String path = uri.getEncodedPath();
if (path != null) {
path = Uri.decode(path);
ContentResolver cr = context.getContentResolver();
StringBuffer buff = new StringBuffer();
buff.append("(").append(MediaStore.Images.ImageColumns.DATA).append("=")