I need to protect the images that I take. from android Training Android I can take a full-sized image. but that is not my need. I need to save the full-size image to the cache directory (/ data / data // cache), and I will delete this cache folder when the user leaves my application.
this is my code that the file was successfully created in the cache directory. but the file size is zero, the image is not recorded
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there 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);
}
source
share