mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-07 23:03:11 +08:00
CB-919: Camera Plugin returned with empty error message
Instead of guarding against a null cursor we detect if the device is using internal or external storage to save the photos and adjust our DB queries accordingly.
This commit is contained in:
parent
a691e9f744
commit
4795133daf
@ -43,6 +43,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Bitmap.CompressFormat;
|
import android.graphics.Bitmap.CompressFormat;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -167,7 +168,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public void takePicture(int returnType, int encodingType) {
|
public void takePicture(int returnType, int encodingType) {
|
||||||
// Save the number of images currently on disk for later
|
// Save the number of images currently on disk for later
|
||||||
this.numPics = queryImgDB().getCount();
|
this.numPics = queryImgDB(whichContentStore()).getCount();
|
||||||
|
|
||||||
// Display camera
|
// Display camera
|
||||||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||||
@ -505,9 +506,9 @@ public class CameraLauncher extends Plugin {
|
|||||||
*
|
*
|
||||||
* @return a cursor
|
* @return a cursor
|
||||||
*/
|
*/
|
||||||
private Cursor queryImgDB() {
|
private Cursor queryImgDB(Uri contentStore) {
|
||||||
return this.cordova.getActivity().getContentResolver().query(
|
return this.cordova.getActivity().getContentResolver().query(
|
||||||
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
contentStore,
|
||||||
new String[] { MediaStore.Images.Media._ID },
|
new String[] { MediaStore.Images.Media._ID },
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -523,7 +524,8 @@ public class CameraLauncher extends Plugin {
|
|||||||
*/
|
*/
|
||||||
private void checkForDuplicateImage(int type) {
|
private void checkForDuplicateImage(int type) {
|
||||||
int diff = 1;
|
int diff = 1;
|
||||||
Cursor cursor = queryImgDB();
|
Uri contentStore = whichContentStore();
|
||||||
|
Cursor cursor = queryImgDB(contentStore);
|
||||||
int currentNumOfImages = cursor.getCount();
|
int currentNumOfImages = cursor.getCount();
|
||||||
|
|
||||||
if (type == FILE_URI) {
|
if (type == FILE_URI) {
|
||||||
@ -534,11 +536,23 @@ public class CameraLauncher extends Plugin {
|
|||||||
if ((currentNumOfImages - numPics) == diff) {
|
if ((currentNumOfImages - numPics) == diff) {
|
||||||
cursor.moveToLast();
|
cursor.moveToLast();
|
||||||
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
|
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
|
||||||
Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
|
Uri uri = Uri.parse(contentStore + "/" + id);
|
||||||
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
|
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if we are storing the images in internal or external storage
|
||||||
|
* @return Uri
|
||||||
|
*/
|
||||||
|
private Uri whichContentStore() {
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
return android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
} else {
|
||||||
|
return android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
|
* Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
|
||||||
*
|
*
|
||||||
|
@ -37,6 +37,7 @@ import android.database.Cursor;
|
|||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -206,7 +207,7 @@ public class Capture extends Plugin {
|
|||||||
*/
|
*/
|
||||||
private void captureImage() {
|
private void captureImage() {
|
||||||
// Save the number of images currently on disk for later
|
// Save the number of images currently on disk for later
|
||||||
this.numPics = queryImgDB().getCount();
|
this.numPics = queryImgDB(whichContentStore()).getCount();
|
||||||
|
|
||||||
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
|
||||||
@ -409,13 +410,13 @@ public class Capture extends Plugin {
|
|||||||
*
|
*
|
||||||
* @return a cursor
|
* @return a cursor
|
||||||
*/
|
*/
|
||||||
private Cursor queryImgDB() {
|
private Cursor queryImgDB(Uri contentStore) {
|
||||||
return this.cordova.getActivity().getContentResolver().query(
|
return this.cordova.getActivity().getContentResolver().query(
|
||||||
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
contentStore,
|
||||||
new String[] { MediaStore.Images.Media._ID },
|
new String[] { MediaStore.Images.Media._ID },
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -423,15 +424,28 @@ public class Capture extends Plugin {
|
|||||||
* to the content store.
|
* to the content store.
|
||||||
*/
|
*/
|
||||||
private void checkForDuplicateImage() {
|
private void checkForDuplicateImage() {
|
||||||
Cursor cursor = queryImgDB();
|
Uri contentStore = whichContentStore();
|
||||||
|
Cursor cursor = queryImgDB(contentStore);
|
||||||
int currentNumOfImages = cursor.getCount();
|
int currentNumOfImages = cursor.getCount();
|
||||||
|
|
||||||
// delete the duplicate file if the difference is 2
|
// delete the duplicate file if the difference is 2
|
||||||
if ((currentNumOfImages - numPics) == 2) {
|
if ((currentNumOfImages - numPics) == 2) {
|
||||||
cursor.moveToLast();
|
cursor.moveToLast();
|
||||||
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
|
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
|
||||||
Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
|
Uri uri = Uri.parse(contentStore + "/" + id);
|
||||||
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
|
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if we are storing the images in internal or external storage
|
||||||
|
* @return Uri
|
||||||
|
*/
|
||||||
|
private Uri whichContentStore() {
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
return android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
|
} else {
|
||||||
|
return android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user