This is an automated email from the ASF dual-hosted git repository.

normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git


The following commit(s) were added to refs/heads/master by this push:
     new 2eaa9a3  fix: return content uris when possible when selecting from 
gallery (#902)
2eaa9a3 is described below

commit 2eaa9a39727991912d325c6d8ad8813506ff1f5a
Author: Norman Breau <nor...@breautek.com>
AuthorDate: Sat Oct 26 00:58:24 2024 -0300

    fix: return content uris when possible when selecting from gallery (#902)
---
 src/android/CameraLauncher.java | 109 ++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 59 deletions(-)

diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index b00b005..b3ba0d6 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -728,77 +728,68 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
             }
         }
 
-        String fileLocation = FileHelper.getRealPath(uri, this.cordova);
-        LOG.d(LOG_TAG, "File location is: " + fileLocation);
-
         String uriString = uri.toString();
-        String finalLocation = fileLocation != null ? fileLocation : uriString;
         String mimeTypeOfGalleryFile = FileHelper.getMimeType(uriString, 
this.cordova);
 
-        if (finalLocation == null) {
-            this.failPicture("Error retrieving result.");
+        // If you ask for video or the selected file cannot be processed
+        // there will be no attempt to resize any returned data.
+        if (this.mediaType == VIDEO  || 
!isImageMimeTypeProcessable(mimeTypeOfGalleryFile)) {
+            this.callbackContext.success(uriString);
         } else {
-            // If you ask for video or the selected file cannot be processed
-            // there will be no attempt to resize any returned data.
-            if (this.mediaType == VIDEO  || 
!isImageMimeTypeProcessable(mimeTypeOfGalleryFile)) {
-                this.callbackContext.success(finalLocation);
-            } else {
 
-                // This is a special case to just return the path as no 
scaling,
-                // rotating, nor compressing needs to be done
-                if (this.targetHeight == -1 && this.targetWidth == -1 &&
-                        destType == FILE_URI && !this.correctOrientation &&
-                        
getMimetypeForEncodingType().equalsIgnoreCase(mimeTypeOfGalleryFile))
-                {
-                    this.callbackContext.success(finalLocation);
-                } else {
-                    Bitmap bitmap = null;
-                    try {
-                        bitmap = getScaledAndRotatedBitmap(uriString);
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    }
-                    if (bitmap == null) {
-                        LOG.d(LOG_TAG, "I either have a null image path or 
bitmap");
-                        this.failPicture("Unable to create bitmap!");
-                        return;
-                    }
+            // This is a special case to just return the path as no scaling,
+            // rotating, nor compressing needs to be done
+            if (this.targetHeight == -1 && this.targetWidth == -1 &&
+                    destType == FILE_URI && !this.correctOrientation &&
+                    
getMimetypeForEncodingType().equalsIgnoreCase(mimeTypeOfGalleryFile))
+            {
+                this.callbackContext.success(uriString);
+            } else {
+                Bitmap bitmap = null;
+                try {
+                    bitmap = getScaledAndRotatedBitmap(uriString);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+                if (bitmap == null) {
+                    LOG.d(LOG_TAG, "I either have a null image path or 
bitmap");
+                    this.failPicture("Unable to create bitmap!");
+                    return;
+                }
 
-                    // If sending base64 image back
-                    if (destType == DATA_URL) {
-                        this.processPicture(bitmap, this.encodingType);
-                    }
+                // If sending base64 image back
+                if (destType == DATA_URL) {
+                    this.processPicture(bitmap, this.encodingType);
+                }
 
-                    // If sending filename back
-                    else if (destType == FILE_URI) {
-                        // Did we modify the image?
-                        if ( (this.targetHeight > 0 && this.targetWidth > 0) ||
-                                (this.correctOrientation && 
this.orientationCorrected) ||
-                                
!mimeTypeOfGalleryFile.equalsIgnoreCase(getMimetypeForEncodingType()))
-                        {
-                            try {
-                                String modifiedPath = 
this.outputModifiedBitmap(bitmap, uri, mimeTypeOfGalleryFile);
-                                // The modified image is cached by the app in 
order to get around this and not have to delete you
-                                // application cache I'm adding the current 
system time to the end of the file url.
-                                this.callbackContext.success("file://" + 
modifiedPath + "?" + System.currentTimeMillis());
-
-                            } catch (Exception e) {
-                                e.printStackTrace();
-                                this.failPicture("Error retrieving image: 
"+e.getLocalizedMessage());
-                            }
-                        } else {
-                            this.callbackContext.success(finalLocation);
+                // If sending filename back
+                else if (destType == FILE_URI) {
+                    // Did we modify the image?
+                    if ( (this.targetHeight > 0 && this.targetWidth > 0) ||
+                            (this.correctOrientation && 
this.orientationCorrected) ||
+                            
!mimeTypeOfGalleryFile.equalsIgnoreCase(getMimetypeForEncodingType()))
+                    {
+                        try {
+                            String modifiedPath = 
this.outputModifiedBitmap(bitmap, uri, mimeTypeOfGalleryFile);
+                            // The modified image is cached by the app in 
order to get around this and not have to delete you
+                            // application cache I'm adding the current system 
time to the end of the file url.
+                            this.callbackContext.success("file://" + 
modifiedPath + "?" + System.currentTimeMillis());
+
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            this.failPicture("Error retrieving image: 
"+e.getLocalizedMessage());
                         }
+                    } else {
+                        this.callbackContext.success(uriString);
                     }
-                    if (bitmap != null) {
-                        bitmap.recycle();
-                        bitmap = null;
-                    }
-                    System.gc();
                 }
+                if (bitmap != null) {
+                    bitmap.recycle();
+                    bitmap = null;
+                }
+                System.gc();
             }
         }
-
     }
 
     /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to