Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): remove usage of Media Store queries #307

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading