6

I'm working with camera in android and I'm new to android camera. I've followed the tutorial from here

Whenever I'll add External storage permission in android manifest, camera saves it in default directory without asking me and I want to save it in my own folder created in sd card. I'd searched a lot but couldn't find any useful link. Please help, any help will be much appreciated. Thank you :)

Tashen Jazbi
  • 1,068
  • 1
  • 16
  • 41
  • Check: http://stackoverflow.com/questions/12952859/capturing-images-with-mediastore-action-image-capture-intent-in-android, where you can give a file name with path. – Paresh Mayani Aug 11 '14 at 11:23

3 Answers3

4

You can add this code in onActivityResult. This will store your image in a folder named "YourFolderName"

String extr = Environment.getExternalStorageDirectory().toString()
            + File.separator + "YourFolderName";
    File myPath = new File(extr, fileName);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(myPath);
        bitMap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        MediaStore.Images.Media.insertImage(context.getContentResolver(),
                bitMap, myPath.getPath(), fileName);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

also need to set permission on Manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
ASP
  • 1,974
  • 3
  • 18
  • 30
1

camera saves it in default directory without asking me and I want to save it in my own folder created in sd card

You can tell the camera where you would like the photo to be stored via EXTRA_OUTPUT, as is shown in the documentation's training module on ACTION_IMAGE_CAPTURE.

There is no requirement for all cameras to store images where you ask it to, though. If the file that you ask for does not exist after the image is taken, you will need to fall back to your existing application logic.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

You can assign a path to write the image data to specific location like this:

String fileName = "/mnt/sdcard/foldername";
FileOutputStream  fos = new FileOutputStream(fileName);
fos.write(data);
Jeff B
  • 8,572
  • 17
  • 61
  • 140
Nish8900
  • 92
  • 4