4
我需要確保我正在拍攝的圖像。從android Android Training 我能夠採取完整大小的圖像。但這不是我的需要。 我需要保存完整大小的圖像緩存dir(/ data/data // cache),並且我將在用戶離開我的應用程序時刪除這些緩存文件夾。如何將捕獲的圖像文件保存到data/data/<package.name>/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);
}
對不起兄弟permisoon DD ..不創建文件在數據/數據/ myapp /緩存中 – AnonymousObject