我想存储从图库中捕获的图像。我不希望他们存储在SD卡上。如何实现这一目标。我有以下代码
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
startActivityForResult(i, CHOOSE_CAMERA_RESULT);
应该是tempuri
?
答案 0 :(得分:2)
tempuri=Uri.fromFile(getOutputFromCamera());
其中getOutputFromCamera()是
private File getOutputFromCamera() {
File storageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
AppConstants.FOLDER_NAME);
if (!storageDir.exists()) {
if (!storageDir.mkdirs()) {
Log.i(TAG, "Failed to create directory " + storageDir
+ AppConstants.FOLDER_NAME);
Toast.makeText(this, "Failed to create Directory",
Toast.LENGTH_SHORT).show();
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File imageFile = new File(storageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".png");
return imageFile;
}
Environment.DIRECTORY_PICTURES 是默认图片目录, AppConstants.FOLDER_NAME 是保存图片的文件夹名称。您可以根据需要更改这些内容。