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

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

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.


> No file path is returned when selecting picture from third party apps
> ---------------------------------------------------------------------
>
>                 Key: CB-10093
>                 URL: https://issues.apache.org/jira/browse/CB-10093
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Camera
>         Environment: Android 6.0, Android 5.1.1, Camera plugin 2.0.0, Cordova 
> 5.4.0
>            Reporter: Ying Wei Loke
>              Labels: android
>
> 1) Camera.getPicture with 
> - source type: PHOTOLIBRARY
> - destination type: FILE_URI
> 2) On the photo library, open other apps from menu (e.g. gallery/file 
> manager/One Drive, etc)
> 3) Select any picture.
> Actual result:
> No file path for the picture selected is returned to the camera plugin.
> Note: Was working previously on plugin version 1.2.0.
> Logs with logcat:
> D/Documents(29453): onActivityResult() code=-1
> V/WindowManager(  543): rotationForOrientationLw(orient=1, last=0); user=0 
> D/CordovaInterfaceImpl(15585): Sending activity result to plugin
> D/CameraLauncher(15585): File locaton is: 
> I/Timeline(15585): Timeline: Activity_idle id: 
> android.os.BinderProxy@16b7c72d time:10419445
> W/System.err(15585): java.io.FileNotFoundException: 
> /storage/emulated/0/Android/data/com.likemindnetworks.apps.teamDental/cache: 
> open failed: EISDIR (Is a directory)
> W/System.err(15585):  at libcore.io.IoBridge.open(IoBridge.java:456)
> W/System.err(15585):  at 
> java.io.FileOutputStream.<init>(FileOutputStream.java:87)
> W/System.err(15585):  at 
> java.io.FileOutputStream.<init>(FileOutputStream.java:127)
> W/System.err(15585):  at 
> java.io.FileOutputStream.<init>(FileOutputStream.java:116)
> W/System.err(15585):  at 
> org.apache.cordova.camera.CameraLauncher.ouputModifiedBitmap(CameraLauncher.java:595)
> W/System.err(15585):  at 
> org.apache.cordova.camera.CameraLauncher.processResultFromGallery(CameraLauncher.java:703)
> W/System.err(15585):  at 
> org.apache.cordova.camera.CameraLauncher.access$000(CameraLauncher.java:66)
> W/System.err(15585):  at 
> org.apache.cordova.camera.CameraLauncher$1.run(CameraLauncher.java:800)
> W/System.err(15585):  at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
> W/System.err(15585):  at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
> W/System.err(15585):  at java.lang.Thread.run(Thread.java:818)
> W/System.err(15585): Caused by: android.system.ErrnoException: open failed: 
> EISDIR (Is a directory)
> W/System.err(15585):  at libcore.io.Posix.open(Native Method)
> W/System.err(15585):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
> W/System.err(15585):  at libcore.io.IoBridge.open(IoBridge.java:442)
> W/System.err(15585):  ... 10 more



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to