我遇到以下脚本的问题。它将图像保存在我想要的文件夹中,但它也将它保存到DCIM文件夹,这是我不想要的。那么我需要更改什么才能将仅保存到我的文件夹中?
**
**
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
// Environment.getDataDirectory()(Environment.)
Environment.getExternalStorageDirectory().toString()
+ "/Android/data/com.itbstudios.shoppinglist/Shopping List");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".itb");
} else {
return null;
}
return mediaFile;
}
**
**
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, 100);
谢谢!
答案 0 :(得分:2)
我的策略:按照问题中的描述捕捉照片,将其保存到内部存储器(data / data / com.package ...)之后将其从公共文件夹(DCIM / MEDIA / 100MEDIA)中删除以下方法(删除该文件夹中最后拍摄的照片......):
private void deleteLastPhotoTaken() {
String[] projection = new String[] {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE };
final Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
null,null, MediaStore.Images.ImageColumns.DATE_TAKEN + "DESC");
if (cursor != null) {
cursor.moveToFirst();
int column_index_data =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String image_path = cursor.getString(column_index_data);
File file = new File(image_path);
if (file.exists()) {
file.delete();
}
}
}