From c9cdd66b7fedec50653e2641509c9181a5ec0f2c Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Thu, 24 Jun 2021 14:22:01 +0200 Subject: [PATCH] image_picker: clean up tmp files in case of error --- .../flutter/plugins/imagepicker/ImagePickerDelegate.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java index abf5ccce1eff..fe88dde99d48 100644 --- a/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java +++ b/packages/image_picker/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java @@ -289,7 +289,10 @@ private void launchTakeVideoWithCameraIntent() { try { activity.startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA); } catch (ActivityNotFoundException e) { -4 finishWithError("no_available_camera", "No cameras available for taking pictures."); + // If we can't delete the file again here, there's not really anything we can do about it. + //noinspection ResultOfMethodCallIgnored + videoFile.delete(); + finishWithError("no_available_camera", "No cameras available for taking pictures."); } } @@ -366,6 +369,9 @@ private void launchTakeImageWithCameraIntent() { try { activity.startActivityForResult(intent, REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA); } catch (ActivityNotFoundException e) { + // If we can't delete the file again here, there's not really anything we can do about it. + //noinspection ResultOfMethodCallIgnored + imageFile.delete(); finishWithError("no_available_camera", "No cameras available for taking pictures."); } }