如何调用系统相机拍摄图片保存在指定文件夹
如题,我想实现用户点击按钮调用相机,拍照后将刚拍的照片,按指定的名称保存在指定的文件夹中,请问要怎样实现啊?我自己写的代码如下,就是不能保存在我指定的文件夹中,而是以默认名称保存在默认的文件夹下,求解。
在线等,有答案马上结贴,谢谢了!
//拍照获取图片,点击拍照调用此方法
protected void doTakePhoto() {
try {
PHOTO_DIR.mkdirs();// 创建照片的存储目录
mCurrentPhotoFile = new File(PHOTO_DIR, getPhotoFileName());// 给新照的照片文件命名
final Intent intent = getTakePickIntent(mCurrentPhotoFile);
startActivityForResult(intent, CAMERA_WITH_DATA);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "e=" + e, Toast.LENGTH_LONG).show();
}
}
public static Intent getTakePickIntent(File f) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
Uri u = Uri.fromFile(f);
intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
return intent;
}
//用当前时间给取得的图片命名
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat(
"'IMG'_yyyy-MM-dd_HH:mm:ss");
return dateFormat.format(date) + ".jpg";
}