Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Inbuild(ActionImageCapture) intent returns null intent .Cannot deliver result {who= null}

I am using the default camera intent to get the image in my app. The problem is camera returns null on onActivityResult() . The ResultCode and RequestCode are returning as expected.

My intent call is:

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 is:

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 the resultCode and responseCode are not null

resultCode = -1
requestCode = 1224

Where I am doing mistake?

But the taken picture is stored in the path (imageUri) as I specified

Is there any other way to get image using camera.

like image 637
Mahendran Avatar asked Nov 23 '11 18:11

Mahendran


Video Answer


1 Answers

Seems you know the imageUri before onActivityResult. This is not correct answer but will work fine.

intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 

// This image uri only you're going to use

So don't use

 Uri imageuri = data.getData();

just use the uri you known.

your code looks like this:

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
  }
}
like image 61
Shadowtech Avatar answered Sep 30 '22 23:09

Shadowtech