2011-12-15 130 views
2

使用默认相机应用的照片和视频将保存在SD卡上。如何更改相机保存路径?

我真的需要知道是否有方法(简单或难)更改路径,以便我可以将这些文件保存在内部存储器

或者如果你知道另一个来自android市场的相机应用程序,可以选择更改路径。

我不需要SD卡解决方案。

回答

5

你可以做这样的事情,

这工作在我的情况..

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

而且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; 
} 

欲了解更多信息看How to capture an image and store it with the native Android Camera

编辑:

在我的代码存储图像上SDCARD,但你可以给根据自己的需要一样,/data/data/<package_name>/files/内部存储路径..

您可以使用Context.getFilesDir()。但请记住,即使这是默认私有的应用程序,所以其他应用程序(包括媒体商店)将无法访问它。也就是说,你总是可以选择使文件世界可读或可写。

Context.getDir()Context.MODE_WORLD_WRITEABLE写一个目录,其他应用程序可以写入。但是,我再次质疑需要将图像数据存储在本地存储中。用户不会理解这一点,除非用户在使用你的应用程序时(不常用)没有安装SD卡。

+0

给予好评殴打我的answser。 =) – 2011-12-15 12:01:38

0

是的,我相信可以从开发人员指南中查看。

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