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.