Github user sencenan commented on a diff in the pull request:

    
https://github.com/apache/cordova-plugin-camera/pull/141#discussion_r46334003
  
    --- Diff: src/android/FileHelper.java ---
    @@ -79,30 +79,59 @@ public static String getRealPath(String uriString, 
CordovaInterface cordova) {
         @SuppressLint("NewApi")
         public static String getRealPathFromURI_API19(Context context, Uri 
uri) {
             String filePath = "";
    +
             try {
    -            String wholeID = DocumentsContract.getDocumentId(uri);
    +            String id;
    +
    +            if (DocumentsContract.isDocumentUri(context, uri)) {
    +                String wholeID = DocumentsContract.getDocumentId(uri);
     
    -            // Split at colon, use second item in the array
    -            String id = wholeID.indexOf(":") > -1 ? wholeID.split(":")[1] 
: wholeID.indexOf(";") > -1 ? wholeID
    -                    .split(";")[1] : wholeID;
    +                // Split at colon, use second item in the array
    +                id = wholeID.indexOf(":") > -1
    +                        ? wholeID.split(":")[1]
    +                        : wholeID.indexOf(";") > -1
    +                        ? wholeID.split(";")[1]
    +                        : wholeID;
    +            } else {
    +                final String uriStr = uri.toString();
    +
    +                if (
    +                        uriStr.startsWith(
    +                                
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString()
    +                        )
    +                ) {
    +                    id = uriStr.substring(uriStr.lastIndexOf("/") + 1);
    +                } else {
    +                    throw new IllegalArgumentException(
    +                            "Cannot get real path from uri: " + uriStr
    +                    );
    +                }
    +            }
     
                 String[] column = { MediaStore.Images.Media.DATA };
     
                 // where id is equal to
                 String sel = MediaStore.Images.Media._ID + "=?";
     
    -            Cursor cursor = 
context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
 column,
    -                    sel, new String[] { id }, null);
    +            Cursor cursor = context.getContentResolver().query(
    --- End diff --
    
    Done. However the existing line's readability is dubious at best.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to