0

We are making an application and in it, we want the ability to save an image. It works great and saves the image automagically on my friends phone which is a samsung galaxy II. But on my Galaxy Nexus it just returns the bitmap data.

The problem is that we are using a function to get the last image path and since Galaxy Nexus won't save the file it just takes the last photo taken with the normal camera application.

This is our code before on result:

private void takePhoto() {
    i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(i, cameraData);
}

So what I want is the know-how to save the image on the sdcard so we can use it later.

Janusz
  • 187,060
  • 113
  • 301
  • 369
Ms01
  • 4,420
  • 9
  • 48
  • 80

1 Answers1

2

The following code should tell the camera to save the image to /sdcard/file.jpg:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mImageCaptureUri = Uri.fromFile(new File(Environment
    .getExternalStorageDirectory(), "file.jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
    mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, 0);
Kai
  • 15,284
  • 6
  • 51
  • 82
  • This makes my application crash I'm afraid. Code: http://pastie.org/3596415 may it be that I need to add some arguments to onActivityResult method? Errors: http://pastie.org/3596421 – Ms01 Mar 14 '12 at 21:03
  • it seems like the get extras makes the program crash since it gives null on the intent -> is it this bug? http://code.google.com/p/android/issues/detail?id=1480 if so, is there any possibility of a solution? – Ms01 Mar 14 '12 at 21:44
  • Is it the whole log? The code worked for me, note that in onActivityForResult you shouldn't call data.getData() since the intent may be null, and instead you should just read the data from mImageCaptureUri. – Kai Mar 15 '12 at 02:40
  • Thats the whole error log. Okay, can you give me an example how to read it? – Ms01 Mar 15 '12 at 11:40
  • 1
    Apparently there are some devices where this method might not work, I recommend you to check this solution instead [link](http://stackoverflow.com/questions/1910608/android-action-image-capture-intent) – Kai Mar 15 '12 at 14:03