I used this page: http://developer.android.com/guide/topics/media/camera.html
To learn how to use the existing camera app to take a photo & return a result for my app.
Sometimes the image saves, sometimes it doesn’t. I’m testing on a Samsung Galaxy Tablet (8.9). If I leave the resolution at the highest setting (2048×1536) & take the photo in portrait, the image never saves. If I take the photo in landscape, the image saves most of the time. If I reduce it to 1024×768, the image saves most of the time (whether portrait or landscape).
Looking for a direction to figure this one out.
private void startCameraForCapture() {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE, getApplicationContext()); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
} catch (Exception e) {
// TODO Auto-generated catch block
_errorMessageTitle = "Error 'StartCamera'";
_errorMessage = "Error: " + e.toString();
showDialog(DIALOG_ERROR_GENERAL);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
showPhoto(2);
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
_errorMessageTitle = "Error in 'Take Photo'";
_errorMessage = "Image Capture Failed";
showDialog(DIALOG_NOTICE_GENERAL);
}
}
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Toast.makeText(getApplicationContext(), "Video not yet supported", Toast.LENGTH_LONG).show();
// Video captured and saved to fileUri specified in the Intent
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the video capture
} else {
// Video capture failed, advise user
}
}
}
Sorry, should have resolved this a while back. The problem was my being a noob to Android.
In the OnCreate method I had a function that was deleting files from the Temp folder I used to store the images from the photo (I added in OnCreate for cleanup purposes).
I found out that OnCreate gets called again when there is an orientation change.
On some Samsung devices, the camera rotates the screen from portrait (which was the only orientation that I was allowing in my app) to landscape.
When the photo was taken, depending on if the user rotated their device prior to selecting “Save Image”, the orientation was changing.
Since the orientation was changing, the function I used to delete the temp files was being called. Felt pretty dumb after I figured it out.