[ 
https://issues.apache.org/jira/browse/CB-9446?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16399619#comment-16399619
 ] 

ASF GitHub Bot commented on CB-9446:
------------------------------------

infil00p closed pull request #112: CB-9446 Fix real path returning null pointer 
on some Samsung devices
URL: https://github.com/apache/cordova-plugin-camera/pull/112
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/android/ExifHelper.java b/src/android/ExifHelper.java
index 5160a2f6..0af0fcd2 100644
--- a/src/android/ExifHelper.java
+++ b/src/android/ExifHelper.java
@@ -53,7 +53,11 @@ Licensed to the Apache Software Foundation (ASF) under one
      * @throws IOException
      */
     public void createInFile(String filePath) throws IOException {
-        this.inFile = new ExifInterface(filePath);
+        if (filePath != null) {
+            this.inFile = new ExifInterface(filePath);
+        } else {
+            throw new IOException("null pointer passed to createInFile");
+        }
     }
 
     /**
@@ -63,7 +67,11 @@ public void createInFile(String filePath) throws IOException 
{
      * @throws IOException
      */
     public void createOutFile(String filePath) throws IOException {
-        this.outFile = new ExifInterface(filePath);
+        if (filePath != null) {
+            this.outFile = new ExifInterface(filePath);
+        } else {
+            throw new IOException("null pointer passed to createOutFile");
+        }
     }
 
     /**
diff --git a/src/android/FileHelper.java b/src/android/FileHelper.java
index 59f890e1..cd4b6ef2 100644
--- a/src/android/FileHelper.java
+++ b/src/android/FileHelper.java
@@ -33,6 +33,7 @@ Licensed to the Apache Software Foundation (ASF) under one
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Locale;
+import android.util.Log;
 
 public class FileHelper {
     private static final String LOG_TAG = "FileUtils";
@@ -54,9 +55,12 @@ public static String getRealPath(Uri uri, CordovaInterface 
cordova) {
             realPath = 
FileHelper.getRealPathFromURI_BelowAPI11(cordova.getActivity(), uri);
 
         // SDK >= 11 && SDK < 19
-        else if (Build.VERSION.SDK_INT < 19)
+        else if (Build.VERSION.SDK_INT < 19) {
             realPath = 
FileHelper.getRealPathFromURI_API11to18(cordova.getActivity(), uri);
-
+            if (realPath == null) {
+                realPath = getRealPathFallback(uri.toString(), cordova);
+            }
+        }
         // SDK > 19 (Android 4.4)
         else
             realPath = 
FileHelper.getRealPathFromURI_API19(cordova.getActivity(), uri);
@@ -126,6 +130,47 @@ public static String getRealPathFromURI_API11to18(Context 
context, Uri contentUr
         return result;
     }
 
+    /**
+     * Returns the real path of the given URI string.
+     * If the given URI string represents a content:// URI, the real path is 
retrieved from the media store.
+     *
+     * @param uriString the URI string of the audio/image/video
+     * @param cordova the current application context
+     * @return the full path to the file
+     */
+    @SuppressWarnings("deprecation")
+    public static String getRealPathFallback(String uriString, 
CordovaInterface cordova) {
+        String realPath = null;
+        try {
+            if (uriString.startsWith("content://")) {
+                String[] proj = { _DATA };
+                Cursor cursor = 
cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, 
null);
+                int column_index = cursor.getColumnIndexOrThrow(_DATA);
+                cursor.moveToFirst();
+                realPath = cursor.getString(column_index);
+                Log.d(LOG_TAG, "getRealPath managedQuery success uri " + 
uriString + " realpath " + realPath);
+                if (realPath == null) {
+                    Log.e(LOG_TAG, "getRealPath Could get real path for URI 
string " + uriString);
+                }
+            } else if (uriString.startsWith("file://")) {
+                realPath = uriString.substring(7);
+                Log.d(LOG_TAG, "getRealPath file:// " + uriString + " realpath 
" + realPath);
+                if (realPath.startsWith("/android_asset/")) {
+                    Log.e(LOG_TAG, "getRealPath Cannot get real path for URI 
string " + uriString + " because it is a file:///android_asset/ URI.");
+                    realPath = null;
+                }
+            } else {
+                realPath = uriString;
+            }
+        } catch (Exception e) {
+            Log.d(LOG_TAG, "getRealPath using uristring could not find real 
path, uriString: " + uriString + " message: " + e.getMessage());
+            realPath = uriString;
+        }
+
+        return realPath;
+    }
+
+
     public static String getRealPathFromURI_BelowAPI11(Context context, Uri 
contentUri) {
         String[] proj = { MediaStore.Images.Media.DATA };
         String result = null;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Samsung device returns null from Cursor in Camera getRealPath
> -------------------------------------------------------------
>
>                 Key: CB-9446
>                 URL: https://issues.apache.org/jira/browse/CB-9446
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-camera
>    Affects Versions: 1.2.1
>         Environment: Samsung 4.1.2 GT-N8010
>            Reporter: Charles Verge
>            Priority: Major
>              Labels: Android, samsung
>             Fix For: 1.2.1
>
>         Attachments: realpath.diff
>
>
> Using a Samsung Galaxy Note GT-N8010 with android 4.1.2 produces an exception 
> in the Exif class. This is due to a filePath being null on line 66 of 
> src/android/ExifHelper.java
> {code} new ExifInterface(filePath){code}
> This error has been introduced when the switch was made to using Cursors. 
> This error did not happen in with the camera plugin bundled with Phone Gap 
> 3.4.
> This has been duplicated by other developers independently 
> http://stackoverflow.com/questions/30616846/phonegap-app-crash-when-take-a-new-photo-with-camera-plugin



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to