2

Photographs and videos using the default camera app are saved on the SD card.

I really need to know if there is a way (easy or hard) to change the path so i can save those files on internal memory.

Or if you know another camera app from android market that has the option to change path.

I don't need SD card solutions.

RobinHood
  • 10,897
  • 4
  • 48
  • 97
Nikitas
  • 1,013
  • 13
  • 27

2 Answers2

6

You can do something like,

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
    // Here you can change yourinternal storage path to store those images..
    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

EDIT:

In my code I store images on SDCARD but you can give Internal storage path as per your need, like, /data/data/<package_name>/files/..

You can use Context.getFilesDir(). But keep in mind that even that is by default private to your app, so other applications (including the media store) will not be able to access it. That said, you always have the option to make files world read or writeable.

also Context.getDir() with Context.MODE_WORLD_WRITEABLE to write a directory that other apps can write into. But again, I question the need to store image data in local storage. Users won't appreciate that, unless users are expected to not have their SD card mounted while using your app (which is not common).

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • hi, is Environment.getExternalStorageDirectory() returns a file on SD Card? I ask this because author asks: change the path so i can save those files on internal memory. – anticafe Dec 15 '11 at 12:06
  • @anticafe - Yes, its return a file On SDCARd, but just check the comment in my code, I mentioned you can give there internal storage path.. – user370305 Dec 15 '11 at 12:18
  • The mobile phone is OEM. From China. It has not an input for SD card. That's why... Thank you for the code! – Nikitas Dec 15 '11 at 18:49
  • @niki - Then you can store images in internal storage of application. Context.getFilesDir() is what you needed.. – user370305 Dec 16 '11 at 05:31
  • @user370305 Because i am so new on android... Where do i put the code you sent me? – Nikitas Dec 16 '11 at 17:40
  • from where you are calling your camera activity, like, on any button's click and the getImageUri() is the general android metod for activity class.. – user370305 Dec 16 '11 at 17:47
  • Can you tell me what the CAPTURE_TITEL is and where do i get it? – user12346352 Jul 18 '19 at 11:36
0

Yes i believe it is possible check out this from the developers guide.

public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;

/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
  return Uri.fromFile(getOutputMediaFile(type));
}

/** Create a File for saving an image or video */
private static Uri getOutputMediaFile(int type){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
          Environment.DIRECTORY_PICTURES), "MyCameraApp");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.

// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
    if (! mediaStorageDir.mkdirs()){
        Log.d("MyCameraApp", "failed to create directory");
        return null;
    }
}

// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE){
    mediaFile = new File(mediaStorageDir.getPath() + File.separator +
    "IMG_"+ timeStamp + ".jpg");
} else if(type == MEDIA_TYPE_VIDEO) {
    mediaFile = new File(mediaStorageDir.getPath() + File.separator +
    "VID_"+ timeStamp + ".mp4");
} else {
    return null;
}

return mediaFile;

}

more info here

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118