I’m having an issue where I’m using the camera app to take a photo & the photo is being deleted before I get a chance to use it in my app. Seems to only happen on certain devices (Samsung Galaxy S2, Samsung Galaxy Tab 10.1, and an LG., don’t remember the model). Each activity in my app sets the screen orientation to portrait (manifest: android:screenOrientation=”portrait”). How I can reproduce problem:
1. Hit “take photo” button from my app, this loads the camera app.
2. Take photo in portrait, which creates the file in the proper location (based on the URI I provided) & displays a preview, in the camera app.
3. Keep device in portrait & hit “Save Image” (which brings you back to my app).
4. When I return to my app, I check if the file exists, and it doesn’t.
If you snap the photo in portrait, then rotate the device to landscape (when the preview is displayed), then hit “Save Image” (while in landscape), the photo is not deleted.
If you snap the photo in landscape (and leave the device in landscape when you hit save), the photo is not deleted.
If you snap the photo in landscape, then rotate the preview to portrait, the photo is not deleted.
I’ve read & googled & have pulled my hair out trying to figure this one out.
When the photo is taken & saved in portrait, when returned back to my app, my app is in landscape, then rotates to portrait.
Any help at all (even if it’s a link to another post that has the answer) is appreciated!
Thank you 🙂
Here is some of my code (when the problem occurs, _cameraFileUri is null):
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
_cameraFileUri = Uri.fromFile(new File(_tempFolder, "tempFromCamera.jpg"));
intent.putExtra(MediaStore.EXTRA_OUTPUT, _cameraFileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
if (_cameraFileUri != null) {
File origFile = new File(_cameraFileUri.getPath());
resizePhoto(origFile);
showPhoto();
} else {
Toast.makeText(getApplicationContext(), "Error: Capture Photo Failed.", Toast.LENGTH_LONG).show();
}
Sorry, this one is resolved. I honestly waited for a week before posting in this forum. I knew that as soon as I posted it, I’d figure out the answer.
The app rotating was the giveaway. It’s recreating the activity, so it was rerunning the onCreate method. For “house keeping” I delete the files in my temp folder. I do this in “onCreate”. So when onCreate was rerunning, it would delete the photo the camera put in the Temp folder.