I set the File path to the following:
File file = new File(Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".png");
ImageCapture.OutputFileOptions outputFileOptions =
new ImageCapture.OutputFileOptions.Builder(file).build();
imageCapture.takePicture(outputFileOptions, Executors.newSingleThreadExecutor(),
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {
// insert your code here.
Log.d("PHOTO", "onImageSaved: saved");
}
@Override
public void onError(ImageCaptureException error) {
// insert your code here.
Log.d("PHOTO", "onError: " + error);
}
});
But for some reason when i click on the capture image button, it jumps into the onError and logs the following:
onError: androidx.camera.core.ImageCaptureException: Failed to write or close the file