【发布时间】:2017-10-26 23:39:17
【问题描述】:
我需要保护我正在拍摄的图像。来自安卓Android Training 我能够拍摄全尺寸图像。但这不是我的需要。 我需要将全尺寸图像保存到缓存目录(/data/data//cache),当用户离开我的应用程序时,我将删除这些缓存文件夹。
这是我的代码,该文件在缓存目录中成功创建。但文件大小为零,没有写入图像
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File file=null;
try {
String fileName = "506214";
file = File.createTempFile(fileName, null, this.getCacheDir());
} catch (IOException e) {
// Error while creating file
}
photoURI = Uri.fromFile(file);
Toast.makeText(this, photoURI.toString(), Toast.LENGTH_SHORT).show();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK){
camera_image.setImageURI(photoURI);
}
super.onActivityResult(requestCode, resultCode, data);
}
【问题讨论】:
标签: android caching android-camera android-file android-camera-intent