6

I use following code take a Picture from camera and to obtain picture's path.

...
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_IMAGE_CAPTURE); // image capture
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult:" + resultCode + " request:" + requestCode);

    switch (requestCode) {
        case CAMERA_IMAGE_CAPTURE:
            Uri selectedImageUri = data.getData();
            userImagePath = getPath(selectedImageUri);
        break;
    }
}

It works good on emulator and on different devices. But on Samsung Galaxy Nexus(4.0.2) it does not launches Camera app. But it returns RESULT_OK to onActivityResult and I see no exceptions in LogCat. Please give me and advice how to solve this issue. Thanks in advance!

tesk_terrus
  • 63
  • 1
  • 1
  • 4
  • http://stackoverflow.com/questions/7277287/default-camera-activity-not-finishing-upon-ok-button-press/14806908#14806908 Just check this link..might be helpful.......The issue might be because of file name or path(which would be better if it has no special characters like spaces) – Satish Feb 11 '13 at 06:50

1 Answers1

7

You are missing EXTRA_OUTPUT, which may impact matters. My Galaxy Nexus can run this sample project successfully, which uses the following code to request the picture:

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

output = new File(dir, "CameraContentDemo.jpeg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));

startActivityForResult(i, CONTENT_REQUEST);
Ziem
  • 6,579
  • 8
  • 53
  • 86
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Hello, unfortunately the same example doesn't work for me. On my Samsung Galaxy S1, after clicking OK on confirmation screen, the intent doesn't come back to my activity. Is there any trick I'm missing? – Tom Burger Aug 09 '12 at 22:28
  • @TomBurger: You should be called with `onActivityResult()`. If not, that's perhaps a Samsung bug. – CommonsWare Aug 09 '12 at 22:33
  • 1
    no, after clicking OK it brings me back to camera application. It comes back to my activity only after clicking Cancel. Btw, the same issue for instance here: http://stackoverflow.com/questions/8221879/how-to-go-back-from-calling-intent – Tom Burger Aug 09 '12 at 22:44
  • @TomBurger: Then that's a Samsung bug. – CommonsWare Aug 09 '12 at 22:48
  • I guess I solved the problem. I described the solution as answer to another question: http://stackoverflow.com/a/13185464/412070 – Tom Burger Nov 01 '12 at 21:12
  • Environment.getExternalStoragePublicDirectory() resolved the main issue, I was getting. :) – AnkitRox Jan 19 '15 at 09:33
  • @TomBurger: This was happening with me. Make sure your phone has directory in which image is going to store. After that okay button will work fine. – Anuj Sharma Dec 16 '15 at 10:16
  • `Environment.getExternalStoragePublicDirectory` is deprecated now. You should use `Context#getExternalFilesDir(String)` instead – Leo DroidCoder Dec 01 '20 at 09:36