nativescript-community / ui-document-picker

A NativeScript plugin that allows you to select files from the device.
https://nativescript-community.github.io/ui-document-picker/
Apache License 2.0
9 stars 8 forks source link

Android 11 : pdf document throw com.android.providers.media.documents throw NullpointerException #7

Open alexist opened 3 years ago

alexist commented 3 years ago

When i select a pdf document, the content uri is

content://com.android.providers.media.documents/document/document%3A30

Logcat logs :

D/[FilePath plugin]:: File - Authority: com.android.providers.media.documents, Fragment: null, Port: -1, Query: null, Scheme: content, Host: com.android.providers.media.documents, Segments: [document, document:30]

FilePath.getPath is looking for a media document

       // MediaProvider
        else if (isMediaDocument(uri)) {

The docId is document:30, type is "document"

But doesn't handle "document"

           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;
            }

=> contenUri is Null

alexist commented 3 years ago

It's look like version 1.1.6 fix this issue, but not yet available in npm. Can you publish this version ?

Thanks,

farfromrefug commented 3 years ago

@alexist it is now released!

kislasi commented 3 years ago

@farfromrefug @alexist now there is no error but no file as well: promise returns: { "files": [ null ], "android": {} } but for media files the promise works and returns: { "files": [ "/storage/emulated/0/Download/sam-moqadam-cU5TUyEaZXQ-unsplash.jpg" ], "android": {} }

farfromrefug commented 3 years ago

@kislasi emulator?

kislasi commented 3 years ago

@farfromrefug yes on android emulator

farfromrefug commented 3 years ago

@kislasi ok test on real device. For me 60% of the time it returns null on emulator.

kislasi commented 3 years ago

@farfromrefug it works on android 10on a real device - but not on android 11 at all

farfromrefug commented 3 years ago

@kislasi ok seems like a bug then. Dont really have time to debug this those days. Could you create a simple repro example?

kislasi commented 3 years ago

openFilePicker({ extensions: ['pdf'], multipleSelection: true, pickerMode: 5 }).then(res => { console.log('SUCCESS', res.files.length > 0); }).catch(err => { console.log('ERROR', err); });

on android 10 the log is: SUCCESS true but on android 11 device (or emulators) the log is:SUCCESS false

@farfromrefug is it what you need?

farfromrefug commented 3 years ago

@kislasi thanks i ll try to reproduce but dont know when though :s

alexist commented 3 years ago

Version 1.1.6 fix my issue for both emulator and device android 11.

Can you attach logcat output ? The logcat log when i select a PDF document in Document folder is :

2021-06-30 08:59:27.778 23695-23695/yourpackage D/[FilePath plugin]:: File - Authority: com.android.providers.media.documents, Fragment: null, Port: -1, Query: null, Scheme: content, Host: com.android.providers.media.documents, Segments: [document, document:30] 2021-06-30 08:59:27.782 23695-23695yourpackageI/[FilePath plugin]:: document

kislasi commented 2 years ago

Hi @alexist sorry for the late replay, please look at the logcat attached: logcat.txt

zamblas commented 2 years ago

I'm also having the same problem, does anyone have a solution?

Ederagp commented 2 years ago

the same problem here, any solution?

farfromrefug commented 2 years ago

@Ederagp working on it. But the bug is not only here but in N too. We need to fix this in N

jacopo69 commented 2 years ago

Hi @farfromrefug do you have any news about the bug?