From 56acd2953bfc6054fdbff6bb69e01f1a4bb68222 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 21 Jun 2012 11:12:30 -0700 Subject: [PATCH 1/8] Adding updated JS --- framework/assets/js/cordova.android.js | 83 +++++++++++--------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index 16dab290..ae20b290 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 347de1a785b7ecbe86c2189343ab2549a9297f9b +// commit 25033fceac7c800623f1f16881b784d19eba69cc -// File generated at :: Fri Jun 08 2012 16:17:50 GMT-0700 (PDT) +// File generated at :: Thu Jun 21 2012 10:45:32 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -190,7 +190,9 @@ var cordova = { fireDocumentEvent: function(type, data) { var evt = createEvent(type, data); if (typeof documentEventHandlers[type] != 'undefined') { - documentEventHandlers[type].fire(evt); + setTimeout(function() { + documentEventHandlers[type].fire(evt); + }, 0); } else { document.dispatchEvent(evt); } @@ -198,7 +200,9 @@ var cordova = { fireWindowEvent: function(type, data) { var evt = createEvent(type,data); if (typeof windowEventHandlers[type] != 'undefined') { - windowEventHandlers[type].fire(evt); + setTimeout(function() { + windowEventHandlers[type].fire(evt); + }, 0); } else { window.dispatchEvent(evt); } @@ -953,8 +957,7 @@ module.exports = function(success, fail, service, action, args) { // If a result was returned if (r.length > 0) { - var v; - eval("v="+r+";"); + var v = JSON.parse(r); // If status is OK, then return value back to caller if (v.status === cordova.callbackStatus.OK) { @@ -1067,28 +1070,6 @@ module.exports = { cordova.addDocumentEventHandler('menubutton'); cordova.addDocumentEventHandler('searchbutton'); - function bindButtonChannel(buttonName) { - // generic button bind used for volumeup/volumedown buttons - return cordova.addDocumentEventHandler(buttonName + 'button', { - onSubscribe:function() { - // If we just attached the first handler, let native know we need to override the button. - if (this.numHandlers === 1) { - exec(null, null, "App", "overrideButton", [buttonName, true]); - } - }, - onUnsubscribe:function() { - // If we just detached the last handler, let native know we no longer override the volumeup button. - if (this.numHandlers === 0) { - exec(null, null, "App", "overrideButton", [buttonName, false]); - } - } - }); - - } - // Inject a listener for the volume buttons on the document. - var volumeUpButtonChannel = bindButtonChannel('volumeup'); - var volumeDownButtonChannel = bindButtonChannel('volumedown'); - // Figure out if we need to shim-in localStorage and WebSQL // support from the native side. var storage = require('cordova/plugin/android/storage'); @@ -1308,7 +1289,7 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) { cameraExport.cleanup = function(successCallback, errorCallback) { exec(successCallback, errorCallback, "Camera", "cleanup", []); -} +}; module.exports = cameraExport; }); @@ -2628,7 +2609,8 @@ module.exports = FileSystem; // file: lib/common/plugin/FileTransfer.js define("cordova/plugin/FileTransfer", function(require, exports, module) { -var exec = require('cordova/exec'); +var exec = require('cordova/exec'), + FileTransferError = require('cordova/plugin/FileTransferError'); /** * FileTransfer uploads a file to a remote server. @@ -2647,6 +2629,8 @@ var FileTransfer = function() {}; * @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false */ FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, trustAllHosts) { + // sanity parameter checking + if (!filePath || !server) throw new Error("FileTransfer.upload requires filePath and server URL parameters at the minimum."); // check for options var fileKey = null; var fileName = null; @@ -2668,7 +2652,12 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro } } - exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]); + var fail = function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status); + errorCallback(error); + }; + + exec(successCallback, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]); }; /** @@ -2679,6 +2668,8 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro * @param errorCallback {Function} Callback to be invoked upon error */ FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) { + // sanity parameter checking + if (!source || !target) throw new Error("FileTransfer.download requires source URI and target URI parameters at the minimum."); var win = function(result) { var entry = null; if (result.isDirectory) { @@ -2693,6 +2684,12 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro entry.fullPath = result.fullPath; successCallback(entry); }; + + var fail = function(e) { + var error = new FileTransferError(e.code, e.source, e.target, e.http_status); + errorCallback(error); + }; + exec(win, errorCallback, 'FileTransfer', 'download', [source, target]); }; @@ -2706,8 +2703,11 @@ define("cordova/plugin/FileTransferError", function(require, exports, module) { * FileTransferError * @constructor */ -var FileTransferError = function(code) { +var FileTransferError = function(code, source, target, status) { this.code = code || null; + this.source = source || null; + this.target = target || null; + this.http_status = status || null; }; FileTransferError.FILE_NOT_FOUND_ERR = 1; @@ -2715,6 +2715,7 @@ FileTransferError.INVALID_URL_ERR = 2; FileTransferError.CONNECTION_ERR = 3; module.exports = FileTransferError; + }); // file: lib/common/plugin/FileUploadOptions.js @@ -3665,21 +3666,6 @@ module.exports = { exec(null, null, "App", "overrideBackbutton", [override]); }, - /** - * Override the default behavior of the Android volume button. - * If overridden, when the volume button is pressed, the "volume[up|down]button" JavaScript event will be fired. - * - * Note: The user should not have to call this method. Instead, when the user - * registers for the "volume[up|down]button" event, this is automatically done. - * - * @param button volumeup, volumedown - * @param override T=override, F=cancel override - */ - overrideButton:function(button, override) { - exec(null, null, "App", "overrideButton", [button, override]); - }, - - /** * Exit and terminate the application. */ @@ -5509,6 +5495,9 @@ define("cordova/plugin/splashscreen", function(require, exports, module) { var exec = require('cordova/exec'); var splashscreen = { + show:function() { + exec(null, null, "SplashScreen", "show", []); + }, hide:function() { exec(null, null, "SplashScreen", "hide", []); } From b339330592fd7a4abffdf85f8fdc8cac64173eba Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Tue, 19 Jun 2012 17:14:05 -0700 Subject: [PATCH 2/8] Added MediaScanner abilities to camera launcher plugin. Now images saved to SD card should show up in the android gallery app right away --- .../org/apache/cordova/CameraLauncher.java | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index e9f4ea8f..ed0f928c 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -42,6 +42,8 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Matrix; import android.graphics.Bitmap.CompressFormat; +import android.media.MediaScannerConnection; +import android.media.MediaScannerConnection.MediaScannerConnectionClient; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; @@ -52,7 +54,7 @@ import android.util.Log; * and returns the captured image. When the camera view is closed, the screen displayed before * the camera view was shown is redisplayed. */ -public class CameraLauncher extends Plugin { +public class CameraLauncher extends Plugin implements MediaScannerConnectionClient { private static final int DATA_URL = 0; // Return base64 encoded string private static final int FILE_URI = 1; // Return file uri (content://media/external/images/media/2 for Android) @@ -82,6 +84,8 @@ public class CameraLauncher extends Plugin { public String callbackId; private int numPics; + + private MediaScannerConnection conn; // Used to update gallery app with newly-written files //This should never be null! //private CordovaInterface cordova; @@ -330,13 +334,13 @@ public class CameraLauncher extends Plugin { // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); - Uri uri = null; + try { - uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { - uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); + this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); @@ -366,24 +370,28 @@ public class CameraLauncher extends Plugin { bitmap = scaleBitmap(getBitmapFromResult(intent)); // Add compressed version of captured image to returned media store Uri - OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); + OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(this.imageUri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { - exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova)); + exif.createOutFile(FileUtils.getRealPathFromURI(this.imageUri, this.cordova)); exif.writeExifData(); } + // Scan for the gallery to update pic refs in gallery + this.scanForGallery(); + // Send Uri back to JavaScript for viewing image - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.success(new PluginResult(PluginResult.Status.OK, this.imageUri.toString()), this.callbackId); } bitmap.recycle(); bitmap = null; System.gc(); checkForDuplicateImage(FILE_URI); + } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); @@ -584,4 +592,26 @@ public class CameraLauncher extends Plugin { public void failPicture(String err) { this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId); } + + private void scanForGallery() { + if(this.conn!=null) this.conn.disconnect(); + this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(), this); + conn.connect(); + } + + @Override + public void onMediaScannerConnected() { + try{ + this.conn.scanFile(this.imageUri.toString(), "image/*"); + } catch (java.lang.IllegalStateException e){ + e.printStackTrace(); + LOG.d(LOG_TAG, "Can;t scan file in MediaScanner aftering taking picture"); + } + + } + + @Override + public void onScanCompleted(String path, Uri uri) { + this.conn.disconnect(); + } } From 9f66ccb5f3f5dc7c2ae3610daf03b22f96173d32 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 20 Jun 2012 11:10:43 -0700 Subject: [PATCH 3/8] merge!!!!11one --- framework/src/org/apache/cordova/CameraLauncher.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index ed0f928c..f2c3e12d 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -81,6 +81,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie private Uri imageUri; // Uri of captured image private int encodingType; // Type of encoding to use private int mediaType; // What type of media to retrieve + private boolean saveToPhotoAlbum; // Should the picture be saved to the device's photo album public String callbackId; private int numPics; @@ -121,6 +122,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (action.equals("takePicture")) { int srcType = CAMERA; int destType = FILE_URI; + this.saveToPhotoAlbum = false; this.targetHeight = 0; this.targetWidth = 0; this.encodingType = JPEG; @@ -134,6 +136,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.targetHeight = args.getInt(4); this.encodingType = args.getInt(5); this.mediaType = args.getInt(6); + this.saveToPhotoAlbum = args.getBoolean(9); if (srcType == CAMERA) { this.takePicture(destType, encodingType); From f6d4402fdc8eae41352f2f268a69e578bf33754f Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 20 Jun 2012 14:12:06 -0700 Subject: [PATCH 4/8] Removing images and saving images to jail if SaveToPhotoAlbum is set to true --- .../org/apache/cordova/CameraLauncher.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index f2c3e12d..d9467fbc 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -338,6 +338,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie ContentValues values = new ContentValues(); values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); + try { this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { @@ -350,6 +351,22 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie return; } } + if (!this.saveToPhotoAlbum) { + File tempFile = new File(this.imageUri.toString()); + Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName())); + + // Clean up initial URI before writing out safe URI + boolean didWeDeleteIt = tempFile.delete(); + if (!didWeDeleteIt) { + int result = this.cordova.getActivity().getContentResolver().delete( + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + MediaStore.Images.Media.DATA + " = ?", + new String[] { this.imageUri.toString() } + ); + LOG.d("TAG!","result is " + result); + } + this.imageUri = jailURI; + } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100) { @@ -378,10 +395,18 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie os.close(); // Restore exif data to file + if (this.encodingType == JPEG) { - exif.createOutFile(FileUtils.getRealPathFromURI(this.imageUri, this.cordova)); + String exifPath; + if (this.saveToPhotoAlbum) { + exifPath = FileUtils.getRealPathFromURI(this.imageUri, this.cordova); + } else { + exifPath = this.imageUri.toString(); + } + exif.createOutFile(exifPath); exif.writeExifData(); } + // Scan for the gallery to update pic refs in gallery this.scanForGallery(); From 66872de8e53e837b1f5e6472e67e134e9c53eace Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 20 Jun 2012 14:38:22 -0700 Subject: [PATCH 5/8] Tacked on file extension to camera file --- framework/src/org/apache/cordova/CameraLauncher.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index d9467fbc..0e86d2c9 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -353,9 +353,10 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } if (!this.saveToPhotoAlbum) { File tempFile = new File(this.imageUri.toString()); - Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName())); + Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName() + "." + (this.encodingType == JPEG ? "jpg" : "png" ))); - // Clean up initial URI before writing out safe URI + // Clean up initial URI before writing out safe URI. + // First try File-based approach to delete. Then use the media delete method. Neither seem to work on ICS right now... boolean didWeDeleteIt = tempFile.delete(); if (!didWeDeleteIt) { int result = this.cordova.getActivity().getContentResolver().delete( @@ -363,7 +364,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie MediaStore.Images.Media.DATA + " = ?", new String[] { this.imageUri.toString() } ); - LOG.d("TAG!","result is " + result); } this.imageUri = jailURI; } From ab3347d25d63ae48dafd7f1e705e4edd0a4fa8f3 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 20 Jun 2012 15:40:40 -0700 Subject: [PATCH 6/8] added . in front of the temp files passed into camera app. presumably this hsould stop the gallery app from picking it up --- framework/src/org/apache/cordova/CameraLauncher.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 0e86d2c9..68389833 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -202,9 +202,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie private File createCaptureFile(int encodingType) { File photo = null; if (encodingType == JPEG) { - photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Pic.jpg"); + photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), ".Pic.jpg"); } else if (encodingType == PNG) { - photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Pic.png"); + photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), ".Pic.png"); } else { throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType); } @@ -310,7 +310,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { - exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Pic.jpg"); + exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); exif.readExifData(); } } catch (IOException e) { From b22c0e5b6d71aefd798ededb4f7781c2d3a2278b Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 21 Jun 2012 12:08:07 -0700 Subject: [PATCH 7/8] Fixed the 0-byte files in gallery. Also fixed exif rewriter for saveToPhotoAlbum:false JPG files. Thanks for your help Simon! --- .../org/apache/cordova/CameraLauncher.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 68389833..d3938ffd 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -333,27 +333,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // If sending filename back else if (destType == FILE_URI) { - // Create entry in media store for image - // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) - ContentValues values = new ContentValues(); - values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); - - - try { - this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException e) { - LOG.d(LOG_TAG, "Can't write to external media storage."); - try { - this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException ex) { - LOG.d(LOG_TAG, "Can't write to internal media storage."); - this.failPicture("Error capturing image - no media storage found."); - return; - } - } if (!this.saveToPhotoAlbum) { File tempFile = new File(this.imageUri.toString()); - Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName() + "." + (this.encodingType == JPEG ? "jpg" : "png" ))); + Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName())); // Clean up initial URI before writing out safe URI. // First try File-based approach to delete. Then use the media delete method. Neither seem to work on ICS right now... @@ -366,6 +348,24 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie ); } this.imageUri = jailURI; + } else { + // Create entry in media store for image + // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) + ContentValues values = new ContentValues(); + values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); + + try { + this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + } catch (UnsupportedOperationException e) { + LOG.d(LOG_TAG, "Can't write to external media storage."); + try { + this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); + } catch (UnsupportedOperationException ex) { + LOG.d(LOG_TAG, "Can't write to internal media storage."); + this.failPicture("Error capturing image - no media storage found."); + return; + } + } } // If all this is true we shouldn't compress the image. @@ -401,7 +401,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (this.saveToPhotoAlbum) { exifPath = FileUtils.getRealPathFromURI(this.imageUri, this.cordova); } else { - exifPath = this.imageUri.toString(); + exifPath = this.imageUri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); From 94568a4ec87219401711bc42e4f549b3bd49e3f9 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 21 Jun 2012 12:37:44 -0700 Subject: [PATCH 8/8] Merging in use of uri variable between Simon and my changes. --- .../src/org/apache/cordova/CameraLauncher.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index d3938ffd..54ab9bbb 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -333,9 +333,10 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // If sending filename back else if (destType == FILE_URI) { + Uri uri; if (!this.saveToPhotoAlbum) { File tempFile = new File(this.imageUri.toString()); - Uri jailURI = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName())); + uri = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", tempFile.getName())); // Clean up initial URI before writing out safe URI. // First try File-based approach to delete. Then use the media delete method. Neither seem to work on ICS right now... @@ -347,7 +348,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie new String[] { this.imageUri.toString() } ); } - this.imageUri = jailURI; } else { // Create entry in media store for image // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) @@ -355,11 +355,11 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); try { - this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { - this.imageUri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); + uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); } catch (UnsupportedOperationException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); this.failPicture("Error capturing image - no media storage found."); @@ -390,7 +390,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie bitmap = scaleBitmap(getBitmapFromResult(intent)); // Add compressed version of captured image to returned media store Uri - OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(this.imageUri); + OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); @@ -399,9 +399,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { - exifPath = FileUtils.getRealPathFromURI(this.imageUri, this.cordova); + exifPath = FileUtils.getRealPathFromURI(uri, this.cordova); } else { - exifPath = this.imageUri.getPath(); + exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); @@ -412,7 +412,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.scanForGallery(); // Send Uri back to JavaScript for viewing image - this.success(new PluginResult(PluginResult.Status.OK, this.imageUri.toString()), this.callbackId); + this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } bitmap.recycle(); bitmap = null;