From 2fd65c21c5754981ed145aea555764562f734494 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Wed, 25 Dec 2024 12:38:27 -0400 Subject: [PATCH] fix: Remove usage of Media Store queries --- src/android/Capture.java | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/src/android/Capture.java b/src/android/Capture.java index f5896157..fd2b56c5 100644 --- a/src/android/Capture.java +++ b/src/android/Capture.java @@ -94,7 +94,6 @@ public class Capture extends CordovaPlugin { private final PendingRequests pendingRequests = new PendingRequests(); - private int numPics; // Number of pictures before capture activity private String audioAbsolutePath; private String imageAbsolutePath; private String videoAbsolutePath; @@ -295,9 +294,6 @@ private void captureAudio(Request req) { private void captureImage(Request req) { if (isMissingCameraPermissions(req)) return; - // Save the number of images currently on disk for later - this.numPics = queryImgDB(whichContentStore()).getCount(); - Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String timeStamp = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()); @@ -428,8 +424,6 @@ public void onImageActivityResult(Request req) { req.results.put(mediaFile); - checkForDuplicateImage(); - if (req.results.length() >= req.limit) { // Send Uri back to JavaScript for viewing image pendingRequests.resolveWithSuccess(req); @@ -529,38 +523,6 @@ private JSONObject createErrorObject(int code, String message) { return obj; } - /** - * Creates a cursor that can be used to determine how many images we have. - * - * @return a cursor - */ - private Cursor queryImgDB(Uri contentStore) { - return this.cordova.getActivity().getContentResolver().query( - contentStore, - new String[] { MediaStore.Images.Media._ID }, - null, - null, - null); - } - - /** - * Used to find out if we are in a situation where the Camera Intent adds to images - * to the content store. - */ - private void checkForDuplicateImage() { - Uri contentStore = whichContentStore(); - Cursor cursor = queryImgDB(contentStore); - int currentNumOfImages = cursor.getCount(); - - // delete the duplicate file if the difference is 2 - if ((currentNumOfImages - numPics) == 2) { - cursor.moveToLast(); - int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1; - Uri uri = Uri.parse(contentStore + "/" + id); - this.cordova.getActivity().getContentResolver().delete(uri, null, null); - } - } - /** * Determine if we are storing the images in internal or external storage * @return Uri