Rahul Gupta-Iwasaki Rahul Gupta-Iwasaki -4 years ago 58
Android Question

Default Camera Activity Not Finishing Upon OK button press

I'm calling the default camera from my activity and then handling the onActivityResult. My code seems to work fine on the LG Ally which doesn't have a confirmation when a picture is taken. However, when I run the same app on the Nexus S, it prompts me with an "Ok", "Retake", or "Cancel" before returning to my activity. While "Cancel" works, returning to my activity without saving the picture, "Ok" doesn't seem to have any effect, not even returning to my activity.

My code below:

private void captureImage() {

String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File path = new File(Environment.getExternalStorageDirectory().getPath() + "/Images/" + (new UserContextAdapter(this)).getUser() + "/");
File file = new File(path, "Image_Story_" + mRowId.toString() + ".jpg");

newImageUri = Uri.fromFile(file);

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, newImageUri);

startActivityForResult(intent, CAPTURE_IMAGE);


public void onActivityResult(int requestCode, int resultCode, Intent intent) {

switch (requestCode) {
switch (resultCode ) {
case 0:
Log.i("CAPTURE", "Cancelled by User");
case -1:
mImageUri = newImageUri;

Answer Source

I think I just had the exact same problem.

If the path to save the picture isn't correct, the camera won't return to your app. Once I made sure the directory exists, everything worked fine. Make sure the directory exists, than it should work.

-- Edit --

I just saw, that you call path.mkdirs(); but I think that it doesn't work. As you can read in the android doc "Note that this method does not throw IOException on failure. Callers must check the return value.". Please be sure to check if the directory really exists.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download