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): close cursors to suppress log warnings #775

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 23 additions & 19 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ public void callTakePicture(int returnType, int encodingType) {
public void takePicture(int returnType, int encodingType)
{
// Save the number of images currently on disk for later
this.numPics = queryImgDB(whichContentStore()).getCount();
Cursor cursor = queryImgDB(whichContentStore());
if (cursor != null) {
this.numPics = cursor.getCount();
cursor.close();
}

// Let's use the intent and see what happens
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Expand All @@ -299,13 +303,13 @@ public void takePicture(int returnType, int encodingType)
applicationId + ".cordova.plugin.camera.provider",
photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
//We can write to this URI, this will hopefully allow us to write files to get to the next step
// We can write to this URI, this will hopefully allow us to write files to get to the next step
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

if (this.cordova != null) {
// Let's check to make sure the camera is actually installed. (Legacy Nexus 7 code)
PackageManager mPm = this.cordova.getActivity().getPackageManager();
if(intent.resolveActivity(mPm) != null)
if (intent.resolveActivity(mPm) != null)
{
this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
}
Expand Down Expand Up @@ -520,7 +524,6 @@ private void processResultFromCamera(int destType, Intent intent) throws IOExcep
return;
}


this.processPicture(bitmap, this.encodingType);

if (!this.saveToPhotoAlbum) {
Expand Down Expand Up @@ -574,8 +577,8 @@ else if (destType == FILE_URI) {
if (this.encodingType == JPEG) {
String exifPath;
exifPath = uri.getPath();
//We just finished rotating it by an arbitrary orientation, just make sure it's normal
if(rotate != ExifInterface.ORIENTATION_NORMAL)
// We just finished rotating it by an arbitrary orientation, just make sure it's normal
if (rotate != ExifInterface.ORIENTATION_NORMAL)
exif.resetOrientation();
exif.createOutFile(exifPath);
exif.writeExifData();
Expand Down Expand Up @@ -800,7 +803,6 @@ private boolean isImageMimeTypeProcessable(String mimeType) {
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

// Get src and dest types from request code for a Camera Activity
int srcType = (requestCode / 16) - 1;
int destType = (requestCode % 16) - 1;
Expand Down Expand Up @@ -1225,21 +1227,23 @@ private void checkForDuplicateImage(int type) {
int diff = 1;
Uri contentStore = whichContentStore();
Cursor cursor = queryImgDB(contentStore);
int currentNumOfImages = cursor.getCount();
if (cursor != null) {
int currentNumOfImages = cursor.getCount();

if (type == FILE_URI && this.saveToPhotoAlbum) {
diff = 2;
}
if (type == FILE_URI && this.saveToPhotoAlbum) {
diff = 2;
}

// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
if ((currentNumOfImages - numPics) == diff) {
cursor.moveToLast();
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
if (diff == 2) {
id--;
// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
if ((currentNumOfImages - this.numPics) == diff) {
cursor.moveToLast();
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
if (diff == 2) {
id--;
}
Uri uri = Uri.parse(contentStore + "/" + id);
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
}
Uri uri = Uri.parse(contentStore + "/" + id);
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
cursor.close();
}
}
Expand Down