I am coding an Android app using Java. I have a function to use an activity intent to capture a image file. I want how to programmatically check if the image file is captured or not.
My function:
private void launchTakeImageWithCameraIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imageFile = createTemporaryWritableImageFile();
path = imageFile.getPath();
Uri imageUri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
grantUriPermissions(intent, imageUri);
try {
activity.startActivityForResult(intent, CAPTURE_IMAGE_REQUEST_ID); // <-- how to check if the image file is captured or not?
} catch (ActivityNotFoundException e) {
try {
if (!imageFile.delete()) {
throw new RuntimeException("failed to delete image file.");
}
} catch (SecurityException exception) {
exception.printStackTrace();
}
result.error(
"no_available_activity",
"no camera available for taking picture.",
null
);
}
}
Any help is appreciated.
In this onActivityResult method, you can check the result code to determine whether the capture was successful
}