From f5e5b4b7b555aa735847ff527b64a43a9dd9d1a1 Mon Sep 17 00:00:00 2001 From: Jhon Arlex Ocampo Cifuentes Date: Tue, 21 Jan 2020 21:04:17 -0500 Subject: [PATCH] fix the problem 2020 Returns the original image in case of cancellation of the image edition --- .../src/main/java/com/getcapacitor/plugin/Camera.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java index ccdba058e..6a4a5e091 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java @@ -1,6 +1,7 @@ package com.getcapacitor.plugin; import android.Manifest; +import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; @@ -53,7 +54,6 @@ public class Camera extends Plugin { static final int REQUEST_IMAGE_CAPTURE = PluginRequestCodes.CAMERA_IMAGE_CAPTURE; static final int REQUEST_IMAGE_PICK = PluginRequestCodes.CAMERA_IMAGE_PICK; static final int REQUEST_IMAGE_EDIT = PluginRequestCodes.CAMERA_IMAGE_EDIT; - // Message constants private static final String INVALID_RESULT_TYPE_ERROR = "Invalid resultType option"; private static final String PERMISSION_DENIED_ERROR = "Unable to access camera, user denied permission request"; @@ -221,7 +221,7 @@ public void openPhotos(final PluginCall call) { } } - public void processCameraImage(PluginCall call, Intent data) { + public void processCameraImage(PluginCall call) { boolean saveToGallery = call.getBoolean("saveToGallery", CameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY); CameraResultType resultType = getResultType(call.getString("resultType")); if(imageFileSavePath == null) { @@ -468,12 +468,15 @@ protected void handleOnActivityResult(int requestCode, int resultCode, Intent da settings = getSettings(savedCall); if (requestCode == REQUEST_IMAGE_CAPTURE) { - processCameraImage(savedCall, data); + processCameraImage(savedCall); } else if (requestCode == REQUEST_IMAGE_PICK) { processPickedImage(savedCall, data); - } else if (requestCode == REQUEST_IMAGE_EDIT) { + } else if (requestCode == REQUEST_IMAGE_EDIT && resultCode == Activity.RESULT_OK) { isEdited = true; processPickedImage(savedCall, data); + } else if (resultCode == Activity.RESULT_CANCELED && imageFileSavePath != null) { + isEdited = true; + processCameraImage(savedCall); } }