From 98a862b4d4527de38928d50c4b6929a1320b1f59 Mon Sep 17 00:00:00 2001 From: Manuel Beck Date: Fri, 31 Jul 2026 12:17:24 +0200 Subject: [PATCH] fix(android): clean up pending camera temp files on cancel/stop - delete pending image and cropped temp files when camera flow is stopped - run cleanup when image selection/capture is canceled - reset pending URI and file path state after best-effort cleanup Generated-By: GPT-5.3-Codex --- src/android/CameraLauncher.java | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index ce6ca2efb..979df868d 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -327,6 +327,8 @@ public void stopCamera() { this.cordova.getActivity().finishActivity((sourceType + 1) * 16 + returnType + 1); } } + + cleanupPendingResultFiles(); } public void takePicture(int returnType, int encodingType) @@ -901,6 +903,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) { }// If cancelled else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } @@ -930,6 +933,7 @@ else if (srcType == CAMERA) { // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } @@ -949,6 +953,7 @@ public void run() { } }); } else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } else { this.failPicture("Selection did not complete!"); @@ -1214,6 +1219,37 @@ private void cleanup(Uri oldImage, Uri newImage, Bitmap bitmap) { System.gc(); } + /** + * Best-effort cleanup for temporary files when capture/selection is cancelled or stopped. + */ + private void cleanupPendingResultFiles() { + deleteIfExists(this.imageUri); + deleteIfExists(this.croppedUri); + + if (this.croppedFilePath != null) { + new File(this.croppedFilePath).delete(); + this.croppedFilePath = null; + } + + this.imageUri = null; + this.croppedUri = null; + } + + private void deleteIfExists(Uri uri) { + if (uri == null) { + return; + } + + try { + String filePath = FileHelper.stripFileProtocol(uri.toString()); + if (filePath != null) { + new File(filePath).delete(); + } + } catch (Exception ignored) { + // Best-effort cleanup only. + } + } + /** * Determine if we are storing the images in internal or external storage *