tags:

views:

107

answers:

2

Hi guys. Good old camera problem, but hope someone figured out by now. So here is the code that I'm using to take pictures with the pre-installed camera app.

The code that start the activity with the intent.

public void onTakePhotoClickHandler(View v){
    m_Intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
    m_Intent.putExtra(MediaStore.EXTRA_OUTPUT, 
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()); // <- For big picture save
    startActivityForResult(m_Intent, TAKE_PICTURE);
}

The onActivityResult() implementation

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_CANCELED) { // <- resultCode = -1 (in debug watch)
        return;
    }
    switch (requestCode) {

    case TAKE_PICTURE: 
        Bundle b = intent.getExtras();
        Bitmap bm = (Bitmap) b.get("data"); // This is the photo <- bm.mHeight = -1 and bm.mWidth = -1 (in debug watch)

        if (b.containsKey(MediaStore.EXTRA_OUTPUT)) { // <- this condition is FALSE
            // Should have to do nothing for big images -- should already saved in MediaStore ... but
            saveImageAndThumbnails(bm);
        } 
        else{
            super.onActivityResult(requestCode, resultCode, intent);
        }
        break;
    }

}

As you can see the problem is that onActivityResult() resultCode is -1 probably there isn't extra data in the returning Intent so there can't be Bitmap pulled out of that data. And the contrition in the "if" command if(b.containsKey(MediaStore.EXTRA_OUTPUT)) is false.

So any clue what I am missing here?

This code is copy-pasted from this tutorials: http://2009.hfoss.org/Tutorial:Camera_and_Gallery_Demo which are a bit outdated but but still works when I run it. All the examples I've seen use this approach?

So what are my opinions on this: 1. I think that there is something about the Uri passed in the Intent's extra data. 2. Maybe something is happening in the onResume() method when the calling activity is displayed after the camera app close and resets some variables.

A: 

Not all devices and not all android versions support parameter MediaStore.EXTRA_OUTPUT. Also result Intent doesn't contain MediaStore.EXTRA_OUTPUT parameter ( source ). File should be saved in the place where you want. Check SDCARD.

Does your Activity is "singleInstance" ( AndroidManifest.xml ) ?

Damian Kołakowski
Is it possible that some versions of Android framework just don't accept MediaStore.EXTRA_OUTPUT in the Intent extra. So if it don't accept it, I need to put the file in the MediaStore that has the Uri that is passed into the Intent to start the camera Activity. The problem is that Android can't pass data with the bigger than 50k trough an Intent.This sounds like a logical explanation
djandreski
A: 

I came up with this solution, and it is working fine for me.

When you call the camera activity, in EXTRA_OUTPUT pass an Uri of a temp file on the storage card. When the camera activity come back, in the onActivityResult() callback method, get that temp file created previously, and add it to the MediaStore. At the end delete the temp file.

djandreski