John Smith
John Smith

Reputation: 2738

Android Getting null image data

I am trying to get the image from the camera. It works fine. I can take a photo and show it on the image view. Actually, I want to send this photo to my server after took. To do that, I try to pull the image in onActivityResult. But, when i check the Intent data, it always return null.Even though, the application runs fine and display the image. Why am I getting null for Intent data? Could you please help me?

Here is the code:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case ACTION_TAKE_PHOTO_B: {
            if (resultCode == RESULT_OK) {
                        Log.e("TAG","data: "+data);
                    display_Photo();            


            //Process the image to send but, data is null   
            }
            break;
        }

    } 
    }

Log cat:

data : Null

Upvotes: 0

Views: 157

Answers (1)

Error 454
Error 454

Reputation: 7315

In the code you are using there are two button onclick handlers that call: dispatchTakePictureIntent(int actionCode)

One button calls it with the enum ACTION_TAKE_PHOTO_B while the other call sit with the enum ACTION_TAKE_PHOTO_S

If you are passing in ACTION_TAKE_PHOTO_B, then the expected result of data in the returned intent is null.

The reason why is that before dispatchTakePictureIntent calls the intent MediaStore.ACTION_IMAGE_CAPTURE, it sets an extra intent parameter based on the actionCode passed in:

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));

According to the documentation for ACTION_IMAGE_CAPTURE:

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field.

So, because the EXTRA_OUTPUT parameter is being set, your image is being written to disk instead of being returned as data in the intent. To get the file location, you can inspect mCurrentPhotoPath which is written to before the intent is launched.

Upvotes: 2

Related Questions