修改部分8.0以上手机无法跳转到裁剪页面的问题
/**
* 调用系统裁剪的方法
*/
private void startPhoneZoom(Uri uri) {
File CropPhoto = new File(App.getInstance().getAppCacheDir(), UUID.randomUUID().toString() + ".jpg");//这个是创建一个截取后的图片路径和名称。
try {
if (CropPhoto.exists()) {
CropPhoto.delete();
}
CropPhoto.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
imageUri = Uri.fromFile(CropPhoto);
Intent intent = new Intent("com.android.camera.action.CROP");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
intent.setDataAndType(uri, "image/*");
//是否可裁剪
intent.putExtra("corp", "true");
//是否压缩
intent.putExtra("scale", true);
//裁剪器高宽比
intent.putExtra("aspectY", 1);
intent.putExtra("aspectX", 1);
//设置裁剪框高宽
intent.putExtra("outputX", 300);
intent.putExtra("outputY", 300);
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true); // no face detection
startActivityForResult(intent, PHOTO_REQUEST_CROP_PHOTO);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PHOTO_REQUEST_CROP_PHOTO && resultCode == RESULT_OK) {
try {
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
String path = ImageUtils.saveBitmap(this, bitmap, App.getInstance().getImageCacheDir());
mUserInfo.setHead_img(path);
mPresenter.updateUserInfo(mUserInfo);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}