In my app I need to capture image with the standard camera app. So, what I did is:
public void TakePhotoProofs() {
// fetching the root directory
root = Environment.getExternalStorageDirectory().toString()
+ "/MyAppStoredImages";
// Creating folders for Image
imageFolderPath = root + "/captured_images";
File imagesFolder = new File(imageFolderPath);
if (!imagesFolder.exists()) {
imagesFolder.mkdirs();
}
// Generating file name by current date
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
imageName = today.format("%Y-%m-%d-%H-%M-%S") + ".png";
// Creating image here
File image = new File(imageFolderPath, imageName);
fileUri = Uri.fromFile(image);
imvPhotoFrame.setTag(imageFolderPath + File.separator + imageName);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(takePictureIntent, CAMERA_IMAGE_REQUEST);
}
In this code snipped I faced with the following issue:
- When the Intent is started I have the standard camera app opened
- Then I press the button to capture image
- In this step I expected to see the Activity with captured image and two buttons "Save" and "Cancel", but instead I see black screen and then the Activity from step (1)
- In the bottom of this Activity there should be couple of frames with thumbnails of previously and currently captured images, but there is only one empty frame.
- When I return to my app in the method
onActivityResult()
the variable fileUri should contain path to captured image that in previous step should be saved in my folder /MyAppStoredImages/captured_images - The sampling image I place in the special ImageView. But it is empty and when I click there to open fullsize image it says "Cannot find an element"
Note: if I run the standard camera app separately, the bottom frames (from step (4)) are not empty.
This behaviour has arisen after I updated my firmware from Android 4.1.2 Jelly Bean to Android 4.2.2 Jelly Bean. With Android 4.1.2 Jelly Bean all images were being captured properly.
Did someone have the same issue? What should I do in this case?
UPDATE: Using the proposition given by @Mohit in this post, I added the following line after putting EXTRA_OUTPUT:
takePictureIntent.putExtra("return-data", true);
Now, it works properly with third-party camera app (I tested with CameraMX). But still I can't use my default camera app (via invocations described above, I can't save captured image. But separately this default app works properly too).
So, if you encountered the same problem, please, refer me to the correct way.
Just in case, this problem arose on the Samsung Galaxy Grand Duos i9082 and its default camera app after upgrading to Android 4.2.2)