The Android Inbuild node (ActionImageCapture) returns a null intent. Unable to pass result {who = null}

I use the default camera intent to get the image in my application. The problem is that the camera returns null on onActivityResult(). ResultCodeand RequestCodecome back as expected.

My intentional call:

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1224;
....
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

OnactivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
    //use imageUri here to access the image
    Uri imageuri = data.getData(); // here is getting crash 
    imageView.setImageFromUri(imageUri);
}
}
}

void setImageFromUri(Uri imgUri){
 ... TODO assign image from uri
}

As I put Log, I got resultCode and responseCode are not null

resultCode = -1
requestCode = 1224

Where am I mistaken?

But the captured image is saved in the path (imageUri), as I pointed out

Is there any other way to get the image using the camera.

+5
source share
1 answer

, onActivityResult. , .

intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 

// uri

 Uri imageuri = data.getData();

uri.

:

if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
  if (resultCode == RESULT_OK) {
//use imageUri here to access the image
imageView.setImageFromUri(imageUri); // imageUri should be global in the activity
  }
}
+10

All Articles