Adding file path extra to image capture intent causes camera app to malfunction on TF300t Android tablet with stock system version 4.2.1. Pressing "done" button does nothing - not even closing camera app activity. No result is returned.
The code I'm using was extracted from Adroid developers site
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imageFile = createImageFile();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
startActivityForResult(cameraIntent, THIS_CAMERA_REQUEST);
With createImageFile() defined as:
private File createImageFile() throws IOException {
File outputDir = getBaseContext().getCacheDir();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "photo_" + timeStamp + "_";
File image = new File(outputDir, imageFileName);
return image;
}
When line
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
is removed, camera app acts as expected.
Is there any resonable workaround ? I would rather not build a camera app myself just to take a photo.
Problematic line:
File outputDir = getBaseContext().getCacheDir();
I've replaced it with:
private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "1mind_" + timeStamp + ".jpg";
File photo = new File(Environment.getExternalStorageDirectory(), imageFileName);
return photo;
}
Turns out, image has to be stored on external storage not in cache dir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With