Effect of keeping cropping active in Gallery ANR app
I wrote an app with a button to trigger an action to take a picture using a method startActivityForResult
. When called onActivityResult
, the application switches to a crop operation to crop the image I just took, also using the method startActivityForResult
. But when I save it, the gallery app always stops, returning an unresponsive app, which causes the resultCode parameter to onActivityResult
be 0 , which is RESULT_CANCELED
.
Code - it's just onCreate()
, onActivityResult()
and the following variables:
public static final int TAKE_PHOTO = 1;
public static final int CROP_PHOTO = 2;
private Button takePhoto;
private ImageView picture;
private Uri imageUri;
OnCreate ():
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
takePhoto = (Button) findViewById(R.id.take_photo);
picture = (ImageView) findViewById(R.id.picture);
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//init File object, to save the image
File outputImage = new File(Environment.getExternalStorageDirectory(), "output_image.jpg");
try{
if(outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
imageUri = Uri.fromFile(outputImage);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, TAKE_PHOTO);
}
});
onActivityResult ():
switch (requestCode){
case TAKE_PHOTO:
if(resultCode == RESULT_OK){
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(imageUri, "image/*");
intent.putExtra("scale", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CROP_PHOTO);
}
break;
case CROP_PHOTO:
Log.d("MainActivity", "CROP_PHOTO_IN, result code : " + resultCode);
if(resultCode == RESULT_OK){
Log.d("MainActivity", "CROP_PHOTO_OK");
try {
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
picture.setImageBitmap(bitmap);
Log.d("MainActivity", "PHOTO_SET");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
break;
default:
break;
}
relevant magazine:
06-28 10: 30: 35.750 1682-1694 /? W / CameraCaptureSession: Session 0: Camera device is already closed: java.lang.IllegalStateException: CameraDevice is already closed on android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError (CameraDeviceImpl.java:1482) on android.hardraimware.pl. .stopRepeating (CameraDeviceImpl.java:677) on android.hardware.camera2.impl.CameraCaptureSessionImpl.close (CameraCaptureSessionImpl.java:328) on android.hardware.camera2.impl.CameraCaptureSessionImpl.fession. lang.Daemons $ FinalizerDaemon.doFinalize (Daemons.java:191) at java.lang.Daemons $ FinalizerDaemon.run (Daemons.java:174) at java.lang.Thread.run (Thread.java:818) 06-28 10 : 30: 38.200 483-561 /? W / AudioTrack: AUDIO_OUTPUT_FLAG_FAST,rejected by customer 06-28 10: 30: 38.205 1589-1782 /? D / skia: --- SkImageDecoder :: Factory returned null 06-28 10: 30: 38,205 1589-1782 /? W / CropActivity: Cannot open register decoder for file: file: ///storage/emulated/0/output_image.jpg java.io.IOException: Image format not supported at android.graphics.BitmapRegionDecoder.nativeNewInstance (native method) at android .graphics.BitmapRegionDecoder.newInstance (BitmapRegionDecoder.java:124) at com.android.gallery3d.filtershow.crop.CropActivity $ BitmapIOTask.doInBackground (CropActivity.java:483) at com.android.gallery.cctivity.filtershow .doInBackground (CropActivity.java:355) at android.os.AsyncTask $ 2.call (AsyncTask.java:292) at java.util.concurrent.FutureTask.run (FutureTask.java:237) at android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolrExecutor ($ Worker.util.concurrent.ThreadPoolrExecutor ( ThreadPoolExecutor.java:587) at java.lang.Thread.run (Thread.java:818) 06-28 10: 30: 38.206 1589-1782 /? D / skia: --- SkImageDecoder :: Factory returned null
In addition, sometimes this does not happen, which is not predictable for me. But this always results in FileNotFoundException
permission-induced failure. I added usage - permission, both read and write, not inside the app label. It did not help.
source to share
No one has answered this question yet
Check out similar questions: