From a7b93206f82a2a2c03c85b06c46c196d38893c8c Mon Sep 17 00:00:00 2001 From: Phil Schilter Date: Mon, 27 Jul 2020 14:10:51 +0200 Subject: [PATCH] fix(android): Provide a file name when an image is saved to the gallery to prevent crash (#3331) --- .../src/main/java/com/getcapacitor/plugin/Camera.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 01fa8a98fb..81c4a05baa 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Camera.java @@ -341,8 +341,9 @@ private void returnResult(PluginCall call, Bitmap bitmap, Uri u) { boolean saveToGallery = call.getBoolean("saveToGallery", CameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY); if (saveToGallery && (imageEditedFileSavePath != null || imageFileSavePath != null)) { try { - String fileToSave = imageEditedFileSavePath != null ? imageEditedFileSavePath : imageFileSavePath; - MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), fileToSave, "", ""); + String fileToSavePath = imageEditedFileSavePath != null ? imageEditedFileSavePath : imageFileSavePath; + File fileToSave = new File(fileToSavePath); + MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), fileToSavePath, fileToSave.getName(), ""); } catch (FileNotFoundException e) { Logger.error(getLogTag(), IMAGE_GALLERY_SAVE_ERROR, e); }