0

i am trying to open camera from my android application and capture image, but it doesn't stored in sdcard. If i capture image from in-build camera then it stored the image on sdcard. using following code : (try to open camera).

Intent intent = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, 1);

in manifest permission :

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

is there something missing in my code?

Thanks in advance.

Hiren Dabhi
  • 3,693
  • 5
  • 37
  • 59

1 Answers1

1

This works in my case..

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri());
startActivityForResult(intent, TAKE_PHOTO_CODE);

And getImageUri()

/**
 * Get the uri of the captured file
 * @return A Uri which path is the path of an image file, stored on the dcim folder
 */
private Uri getImageUri() {
    // Store image in dcim
    File file = new File(Environment.getExternalStorageDirectory() + "/DCIM", CAPTURE_TITLE);
    Uri imgUri = Uri.fromFile(file);

    return imgUri;
}

For more info look at How to capture an image and store it with the native Android Camera

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151