From c1c907596233efd175ff611d35d82c53fe157577 Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 20 Jun 2012 12:20:37 -0400 Subject: [PATCH] CB-919: Camera Plugin returned with empty error message Guarding against null cursor. --- .../org/apache/cordova/CameraLauncher.java | 22 ++++++++++--------- framework/src/org/apache/cordova/Capture.java | 16 ++++++++------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 3520247b..3d43b11c 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -524,18 +524,20 @@ public class CameraLauncher extends Plugin { private void checkForDuplicateImage(int type) { int diff = 1; Cursor cursor = queryImgDB(); - int currentNumOfImages = cursor.getCount(); + if (cursor != null) { + int currentNumOfImages = cursor.getCount(); - if (type == FILE_URI) { - diff = 2; - } + if (type == FILE_URI) { + 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))) - 1; - Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id); - this.cordova.getActivity().getContentResolver().delete(uri, null, null); + // 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))) - 1; + Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id); + this.cordova.getActivity().getContentResolver().delete(uri, null, null); + } } } diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java index cd115d40..5898dc87 100644 --- a/framework/src/org/apache/cordova/Capture.java +++ b/framework/src/org/apache/cordova/Capture.java @@ -424,14 +424,16 @@ public class Capture extends Plugin { */ private void checkForDuplicateImage() { Cursor cursor = queryImgDB(); - int currentNumOfImages = cursor.getCount(); + if (cursor != null) { + 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(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id); - this.cordova.getActivity().getContentResolver().delete(uri, null, null); + // 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(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id); + this.cordova.getActivity().getContentResolver().delete(uri, null, null); + } } } }