Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files downloaded with Chrome cannot be used in Android Pie #223

Closed
lini opened this issue Nov 5, 2018 · 10 comments
Closed

Files downloaded with Chrome cannot be used in Android Pie #223

lini opened this issue Nov 5, 2018 · 10 comments

Comments

@lini
Copy link
Contributor

lini commented Nov 5, 2018

Which platform(s) does your issue occur on?

  • Android version 9
  • Pixel 2

Please, tell us how to recreate the issue in as much detail as possible.

  • Download a file using Chrome.
  • Open Image Picker demo.
  • Go to Downloads, select file.
  • App crashes with the following exception:
JS: Error: java.lang.IllegalArgumentException: Unknown URI: content://downloads/public_downloads/24
JS:     android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
JS:     android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
JS:     android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
JS:     android.content.ContentResolver.query(ContentResolver.java:802)
JS:     android.content.ContentResolver.query(ContentResolver.java:752)
JS:     android.content.ContentResolver.query(ContentResolver.java:710)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:983)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:967)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:959)
JS:     com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:66)JS:     android.app.Activity.dispatchActivityResult(Activity.java:7454)
JS:    ...
@leoncc
Copy link

leoncc commented Nov 18, 2018

In imagepicker.android.ts we have:

            // DownloadsProvider
            else if (UriHelper.isDownloadsDocument(uri)) {
                id = DocumentsContract.getDocumentId(uri);
                // Since Oreo the downloads id may be a raw string,
                // containing the file path:
                if (id.indexOf("raw:") !== -1) {
                    return id.substring(4, id.length);
                }
                contentUri = android.content.ContentUris.withAppendedId(
                    android.net.Uri.parse("content://downloads/public_downloads"), long(id));

                return UriHelper.getDataColumn(contentUri, null, null);
            }

that we can maybe replace with:

            else if (UriHelper.isDownloadsDocument(uri)) {
                return UriHelper.getDataColumn(uri, null, null);
            }

But a bigger problem awaits:

    private static getDataColumn(uri: android.net.Uri, selection, selectionArgs) {
        let cursor = null;
        let columns = [android.provider.MediaStore.MediaColumns.DATA];
        let filePath;

        try {
            cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
            if (cursor != null && cursor.moveToFirst()) {
                let column_index = cursor.getColumnIndexOrThrow(columns[0]);
                filePath = cursor.getString(column_index);
     ......
     ......

On Android 7, the columns for the rows of cursor are:
_id, _data, _size, _display_name, mime_type, title, date_added, date_modified.............

On Android 8.1 (I have a Go edition) the _data and a lot of the other columns are not there anymore.

So in the query it is looking for _data, but it does not exist.

I guess the only way to fix this is to copy the contents to a stream and save it in a cache directory or something.

I added this debug code to determine the columns returned:

for(var i=0; i<cursor.getColumnCount();i++)
{
    console.log(`Column Name: ${cursor.getColumnName(i)}`);
}

@stevenspiel
Copy link

I'm also having this issue. What workaround would you suggest for now?

@leoncc
Copy link

leoncc commented Dec 7, 2018

I did a ugly one. I replaced ..../node_modules/nativescript-imagepicker/imagespicker.android.js with the file in the zip below. As you know with the next tns plugin add... it will be gone.

imagepicker.android.js.zip

@stevenspiel
Copy link

Thanks @leoncc! I replaced the contents of the file, but I'm still getting the error. Is there some other npm command I need to run to register the changes? If not, I'll just hold out for the next release.

@leoncc
Copy link

leoncc commented Dec 9, 2018

Try deleting the platforms folder (the one of your project not in node_modules) and then do tns run android again.

@vakrilov vakrilov added this to Backlog in Plugins Team Apr 15, 2019
@remcom
Copy link

remcom commented May 8, 2019

I also run into the same issue as described. The temporary fix posted in the file by @stevenspiel is working for me but it would by nice to have a more permanent solution in the repo.

@lennonphosfato
Copy link

I'm having the same problem the plugin will be updated with this solution above?

@Jarrich
Copy link

Jarrich commented May 23, 2019

Same issue here!

@VladimirAmiorkov
Copy link
Contributor

Hi all,

This issue has not been added to our immediate plans so if anyone is upto the task if contributing to this project we will be more than happy to review and merge a PR that resolves the above issue. For details on how you could contribute read this section.

@tgpetrov tgpetrov moved this from Inbox to Review / QA in Plugins Team Jul 22, 2019
@zbranzov zbranzov moved this from Review / QA to Ready for Release in Plugins Team Jul 23, 2019
@zbranzov
Copy link
Contributor

zbranzov commented Aug 1, 2019

The fix is published in nativescript-imagepicker@6.3.0

@zbranzov zbranzov closed this as completed Aug 1, 2019
Plugins Team automation moved this from Ready for Release to Done Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Plugins Team
  
Done
Development

No branches or pull requests

8 participants