Skip to content

Commit

Permalink
fix: Remove usage of Media Store queries
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Dec 25, 2024
1 parent 8b25798 commit 2fd65c2
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/android/Capture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fd65c2

Please sign in to comment.