You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Dagfinn Parnas (JIRA)" <ji...@apache.org> on 2016/03/15 08:54:33 UTC

[jira] [Commented] (CB-10857) Camera.getPicture return null for Google Drive (camera 2.1.1)

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

Dagfinn Parnas commented on CB-10857:
-------------------------------------

Have debugged the issue. 
FileHelper.getRealPathFromURI_API19 is the method which handles the logic. 
In this method DocumentsContract.isDocumentUri(context, uri) returns true, but none of the sub if-statements match and therefore it returns null. 

I believe it in this case should return the raw uri via uri.toString(). Example uri.toString() 
content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D3000

If you pass the example uri string above to the File plugin, the file plugin is able to read both images and files with no issues. 

Suggest change the following code of FileHelper
{code}
    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is a GoogleDrive document
     */
    public static boolean isGoogleDriveDocument(Uri uri) {
        return "com.google.android.apps.docs.storage".equals(uri.getAuthority());
    }

    @SuppressLint("NewApi")
    public static String getRealPathFromURI_API19(final Context context, final Uri uri) {

        // DocumentProvider
        if ( DocumentsContract.isDocumentUri(context, uri)) {

            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }

                // TODO handle non-primary volumes
            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[] {
                        split[1]
                };

                return getDataColumn(context, contentUri, selection, selectionArgs);
            }else if (isGoogleDriveDocument(uri)){
                return uri.toString();
            }
        }
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {

            // Return the remote address
            if (isGooglePhotosUri(uri))
                return uri.getLastPathSegment();

            return getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }

        return null;
    }
{code]


> Camera.getPicture return null for Google Drive (camera 2.1.1)
> -------------------------------------------------------------
>
>                 Key: CB-10857
>                 URL: https://issues.apache.org/jira/browse/CB-10857
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Camera
>    Affects Versions: 2.1.1
>         Environment: Android - Tested on 6.0.1
>            Reporter: Dagfinn Parnas
>              Labels: android, mustfix, reproduced, triaged
>         Attachments: Filepicker_google_drive.png
>
>
> Camera.getPicture returns null for pictures and other files when using Google Drive in version 2.1.1. Other sources in the generic file picker such as Images, Photos and Astro File Manager works. 
> The camera plugin gets a null value in processResultFromGallery
> 03-14 10:21:00.066: D/CameraLauncher(21662): File locaton is: null
> The return value from the file picker is
> content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D3000 (see android log below)
> Code sample:
> {code}
>         navigator.camera.getPicture(onPhotoURISuccess, onFail, {
>             quality: 50,
>             correctOrientation: true,
>             destinationType: destinationType.FILE_URI,
>             sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
>             mediaType: Camera.MediaType.ALLMEDIA,
>         });
> {code}
> Android log: 
> {code}
> 03-14 10:48:31.969: I/ActivityManager(914): Displayed com.android.documentsui/.DocumentsActivity: +146ms (total +172ms)
> 03-14 10:48:31.974: D/Documents(19828): userMode=0, userSortOrder=0 --> mode=2, sortOrder=2
> 03-14 10:48:40.310: D/Documents(19828): userMode=0, userSortOrder=0 --> mode=1, sortOrder=1
> 03-14 10:48:44.279: D/NetlinkSocketObserver(914): NeighborEvent{elapsedMs=447463541, 10.4.67.1, [FEA087606419], RTM_NEWNEIGH, NUD_STALE}
> 03-14 10:48:45.778: D/Documents(19828): userMode=0, userSortOrder=0 --> mode=1, sortOrder=1
> 03-14 10:48:46.192: D/ConnectivityService(914): updateNetworkScore for NetworkAgentInfo [WIFI () - 148] to 55
> 03-14 10:48:48.832: I/Atfwd_Sendcmd(1677): AtCmdFwd service not ready - Exhausted retry attempts - :6
> 03-14 10:48:48.833: I/Atfwd_Daemon(1677): result : -1 	 ,Init step :2 	 ,qmiErrorCode: 0
> 03-14 10:48:49.211: D/ConnectivityService(914): updateNetworkScore for NetworkAgentInfo [WIFI () - 148] to 56
> 03-14 10:48:49.243: D/Documents(19828): userMode=0, userSortOrder=0 --> mode=1, sortOrder=1
> 03-14 10:48:52.028: D/Documents(19828): onFinished() [content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3D3000]
> 03-14 10:48:52.049: D/CordovaInterfaceImpl(2469): Sending activity result to plugin
> 03-14 10:48:52.051: D/CameraLauncher(2469): File locaton is: null
> 03-14 10:48:52.056: I/chromium(2469): [INFO:CONSOLE(39)] "onPhotoURISuccess: null", source: file:///android_asset/www/neptune/public/application/z_cats_login_bouvet/js/loglevel-persistlogstrings.js (39)
> {code}
> Related to https://issues.apache.org/jira/browse/CB-10270
> PS Updated android log



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

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