From d8984e2e7c0407584f33fb78db25094327114dfd Mon Sep 17 00:00:00 2001 From: Bastien MARSAUD Date: Mon, 15 Apr 2024 12:19:39 +0200 Subject: [PATCH] fix(android): handle cancelled media capture intent (#291) --- src/android/Capture.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/android/Capture.java b/src/android/Capture.java index 43bcc57f..364e784f 100644 --- a/src/android/Capture.java +++ b/src/android/Capture.java @@ -332,8 +332,8 @@ private void captureVideo(Request req) { public void onActivityResult(int requestCode, int resultCode, final Intent intent) { final Request req = pendingRequests.get(requestCode); - // Result received okay - if (resultCode == Activity.RESULT_OK) { + // Result received okay or the capture image intent has been cancelled + if (resultCode == Activity.RESULT_OK || (req.action == CAPTURE_IMAGE && intent == null)) { Runnable processActivityResult = new Runnable() { @Override public void run() { @@ -419,6 +419,17 @@ public void onImageActivityResult(Request req) { return; } + long size = 0; + try { + size = mediaFile.getLong("size"); + } catch (JSONException e) { + // noop + } + if (size == 0) { + pendingRequests.resolveWithFailure(req, createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: file is empty")); + return; + } + req.results.put(mediaFile); checkForDuplicateImage();