This is an automated email from the ASF dual-hosted git repository. GitToTheHub pushed a commit to branch pr-android-cleanup-files-after-cancel-stop in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
commit 98a862b4d4527de38928d50c4b6929a1320b1f59 Author: Manuel Beck <[email protected]> AuthorDate: Fri Jul 31 12:17:24 2026 +0200 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 ce6ca2e..979df86 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -327,6 +327,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect this.cordova.getActivity().finishActivity((sourceType + 1) * 16 + returnType + 1); } } + + cleanupPendingResultFiles(); } public void takePicture(int returnType, int encodingType) @@ -901,6 +903,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect }// If cancelled else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } @@ -930,6 +933,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } @@ -949,6 +953,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect } }); } else if (resultCode == Activity.RESULT_CANCELED) { + cleanupPendingResultFiles(); this.failPicture("No Image Selected"); } else { this.failPicture("Selection did not complete!"); @@ -1214,6 +1219,37 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect 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 * --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
