From b22c0e5b6d71aefd798ededb4f7781c2d3a2278b Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 21 Jun 2012 12:08:07 -0700 Subject: [PATCH] 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();