prabudevarrajan / nativescript-plugin-filepicker

NativeScript file picker wrapper for both iOS and Android
Apache License 2.0
3 stars 5 forks source link

The plugin stopped working with text documents #2

Open Lyoulka opened 3 years ago

Lyoulka commented 3 years ago

Hello! I'm working with your plugin, and this week it just stopped working with any text documenets. I'm always getting [Error: java.lang.NullPointerException: uri]. Moreover, while I was trying to realize what had happend I figured out that when I set extensions: ["pdf", "doc", "docx"] it still allowed me to download mp4 files.

Although I have found how to fix URI problem I would really appreciate it if you could check my solution and possibly update the plugin.

Solution: I noticed that in plugin-filepicker.android.js function UriHelper.isMediaDocument(uri) returns true for text documents and there're not any condition for that. So I just added new condition else if ("content" === uri.getScheme()) { return UriHelper.getDataColumn(uri, null, null, true); } in this part of code:

else if (UriHelper.isMediaDocument(uri)) {
                docId = DocumentsContract.getDocumentId(uri);
                var split = docId.split(":");
                type = split[0];
                id = split[1];
                if ("image" === type) {
                    contentUri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                }
                else if ("video" === type) {
                    contentUri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                }
                else if ("audio" === type) {
                    contentUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                } 
                // my condition
                else if ("content" === uri.getScheme()) {
                    return UriHelper.getDataColumn(uri, null, null, true);
                }
                var selection = "_id=?";
                var selectionArgs = [id];
                return UriHelper.getDataColumn(contentUri, selection, selectionArgs, false);
            }

and now it works as before. Do you have any ideas about this? Thank you in advance for your help :)

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

r0nneberg commented 2 years ago

thanks a lot for your approach! worked for me.