Removing images and saving images to jail if SaveToPhotoAlbum is set to true


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/8a5ed3bd
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/8a5ed3bd
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/8a5ed3bd

Branch: refs/heads/mediascanner
Commit: 8a5ed3bde917203bd5b4382fbd264eb908634355
Parents: b49d822
Author: Fil Maj <[email protected]>
Authored: Wed Jun 20 14:12:06 2012 -0700
Committer: Fil Maj <[email protected]>
Committed: Wed Jun 20 14:12:06 2012 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CameraLauncher.java     |   27 ++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/8a5ed3bd/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java 
b/framework/src/org/apache/cordova/CameraLauncher.java
index 1845358..c8df6cc 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -342,6 +342,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) {
@@ -354,6 +355,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;
+                        }
 
                         // Add compressed version of captured image to 
returned media store Uri
                         OutputStream os = 
this.cordova.getActivity().getContentResolver().openOutputStream(this.imageUri);
@@ -361,10 +378,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();

Reply via email to