我尝试实现帮助用户捕获照片并裁剪图片或选择图像并裁剪它的应用程序,应用程序在android 4.4中成功运行但是当尝试在另一台设备5.1中测试它时,在裁剪图像后出现Dialog并选择保存选项包含以下消息unfortunately gallery has stopped
以下代码我如何开始裁剪。
public void ImageCropFunction() {
try {
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri, "image/*");
CropIntent.putExtra("crop", "true");
CropIntent.putExtra("scaleUpIfNeeded", true);
CropIntent.putExtra("return-data", true);
startActivityForResult(CropIntent, 1);
} catch (ActivityNotFoundException e) {
}
}
从相机拍摄照片
public void ClickImageFromCamera() {
CamIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory(),
"file" + String.valueOf(System.currentTimeMillis()) + ".jpg");
uri = Uri.fromFile(file);
CamIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
CamIntent.putExtra("return-data", true);
startActivityForResult(CamIntent, 0);
}
并从画廊中挑选图片
public void GetImageFromGallery() {
GalIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(GalIntent, "Select Image From Gallery"), 2);
}
并使用
请求运行时权限public void EnableRuntimePermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(StartUp.this,
Manifest.permission.CAMERA)) {
Toast.makeText(StartUp.this, "CAMERA permission allows us to Access CAMERA app", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(StartUp.this, new String[]{
Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,}, RequestPermissionCode);
}
}
并获取选择图像或请求权限的结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK) {
ImageCropFunction();
} else if (requestCode == 2) {
if (data != null) {
uri = data.getData();
ImageCropFunction();
}
} else if (requestCode == 1) {
if (data != null) {
Bundle bundle = data.getExtras();
Bitmap bitmap = bundle.getParcelable("data");
this.bitmap = bitmap;
imageView.setImageBitmap(bitmap);
buttonDetect.setVisibility(View.VISIBLE);
}
}
}
崩溃发生后Logcat没有显示任何问题只显示此
START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView
有人可以帮忙吗?