获得本地图片地址(针对比如一加不能正常常规获得)
关键问题在于进入图库获得图片
Intent intent = new Intent(Intent.ACTION_PICK); //intent.setType("image/*");//相片类型 。 intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);//使用这句一加就能获得 startActivityForResult(intent, code_gotoAlbum);
Uri uri = data.getData(); path = ImageUtil.getRealPathFromURI(context, uri);
public static String getRealPathFromURI(Context context, Uri contentUri) { if (null == contentUri) { return null; } String res = null; String[] proj = {MediaStore.Images.Media.DATA}; final String scheme = contentUri.getScheme(); if (scheme == null) { res = contentUri.getPath(); return res; } if (ContentResolver.SCHEME_FILE.equals(scheme)) { res = contentUri.getPath(); return res; } if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); cursor.moveToFirst(); if (null != cursor) { if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (column_index > -1) { res = cursor.getString(column_index); Log.w("test",res); } } } cursor.close(); } Log.w("test", "res:" + res); return res; }