codekidX / storage-chooser

Lets user choose files in internal or external storage with just few lines of code.
Mozilla Public License 2.0
721 stars 153 forks source link

[BUG] Android 11 Crash #127

Open OPunktSchmidt opened 4 years ago

OPunktSchmidt commented 4 years ago

This library seems to crash on Android 11. Is it planned to fix this? I dont get this error on other Android Versions

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NullPointerException: Attempt to get length of null array
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.populateList(ChooserDialogFragment.java:262)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.initListView(ChooserDialogFragment.java:115)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.getLayout(ChooserDialogFragment.java:85)
        at com.codekidlabs.storagechooser.fragments.ChooserDialogFragment.onCreateDialog(ChooserDialogFragment.java:300)
        at android.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:417)
        at android.app.Fragment.performGetLayoutInflater(Fragment.java:1322)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)
        at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
        at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
        at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
xiyurain commented 3 years ago

Same problem : (

oluwabajio commented 3 years ago

Same Problem Kindly fix

nikeshkumarbedia commented 3 years ago

Same problem with android 11. Kindly update on this.

mveroukis commented 3 years ago

+1. My app also crashes with the exact same exception on Android 11. It's possible that the bug is in Android 11, I feel it's a bit of a buggy release, but still, it would be nice to have a work around or something. Thanks.

NoelChew commented 3 years ago

+1

mveroukis commented 3 years ago

Looks like someone has a potential fix: https://github.com/sfilmak/storage-chooser/commit/c43a6b534855da6b2e87fa0f25d0c67d40c84fbf

OPunktSchmidt commented 3 years ago

Has anyone found an alternative for this library? I don't think the bug will be fixed in the near future.

mveroukis commented 3 years ago

No need for an alternative. Someone else (sfilmak) fixed it. I forked his fork, tagged it and created a release for it. Since the original library uses jitpack, it's really easy to switch over to use your own fork of it. I just changed out: com.github.codekidX:storage-chooser:2.0.4.4

and replaced it with: com.github.mveroukis:storage-chooser:2.0.4.4a

The "a" at the end is my own tag, otherwise it would continue using the same version as the original. Now my app works in Android 11. As a bonus, it also uses newer versions of it's dependencies and targets API 30.

NoelChew commented 3 years ago

Good idea @mveroukis The commit https://github.com/sfilmak/storage-chooser/commit/c43a6b534855da6b2e87fa0f25d0c67d40c84fbf contains other changes that broke my build. I have forked and uploaded a commit with the only change that fixes the crash on Android 11 devices. Here's the my version:

https://github.com/NoelChew/storage-chooser/commit/f0ffc9ce5df35c9597eebc3b819093b74136e082

implementation 'com.github.noelchew:storage-chooser:2.0.4.4a'
1stmetro commented 3 years ago

I did manage to get the original code working with the external drive, a bit of a hack but its working ok for me.

I did step back for API 28 as there wasn't much point going to 29 or 30 due to scoped storage and this version of the app isnt going on google play so the api version doesnt matter.

If anyone is interested i can post the hack and maybe someone will improve upon it, it was a quick mod to the existing code.

Shabinder commented 3 years ago

Updated Dependencies, Optimised and compressed Resources and New Publishing Plugin

implementation("com.github.shabinder:storage-chooser:2.0.4.45")

mendhak commented 3 years ago

FWIW I've also got a fork of this repo, with some additional fixes and changes

If anyone wants:

implementation 'com.github.mendhak:storage-chooser:2.0.4.4b'
kollabz commented 2 years ago

Hi. @mendhak , i use your 'com.github.mendhak:storage-chooser:2.0.4.4b' and it's work good for open 'ChooserDialogFragment'. But if i use 'customFilter' or 'filter' in chooser builder, I have error at 'UniversalFileFilter.java' and 'SecondaryChooserFragment.java'.

code:

    Content c = new Content();
    c.setInternalStorageText(getString(R.string.DIALOG_STORAGE_TEXT));
    c.setCancelLabel(getString(R.string.DIALOG_CANCEL));
    c.setSelectLabel(getString(R.string.DIALOG_SELECT));
    c.setOverviewHeading(getString(R.string.DIALOG_OVERVIEW_HEADING_IMPORT));

    ArrayList<String> formats = new ArrayList<>();
    formats.add("txt");

    builder.withActivity(this)
            .withFragmentManager(getFragmentManager())
            .setMemoryBarHeight(1.5f)
            .customFilter(formats)
            .withContent(c)
            .withMemoryBar(true)
            .allowCustomPath(true)
            .showHidden(true)
            .hideFreeSpaceLabel(true)
            .setType(StorageChooser.FILE_PICKER);
    chooser = builder.build();

log: java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$4.done(AsyncTask.java:415) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923) Caused by: java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:220) at com.codekidlabs.storagechooser.filters.UniversalFileFilter.findInDirectory(UniversalFileFilter.java:98) at com.codekidlabs.storagechooser.filters.UniversalFileFilter.findInDirectory(UniversalFileFilter.java:121) at com.codekidlabs.storagechooser.filters.UniversalFileFilter.accept(UniversalFileFilter.java:53) at java.io.File.listFiles(File.java:1300) at com.codekidlabs.storagechooser.fragments.SecondaryChooserFragment$FileFilterTask.doInBackground(SecondaryChooserFragment.java:822) at com.codekidlabs.storagechooser.fragments.SecondaryChooserFragment$FileFilterTask.doInBackground(SecondaryChooserFragment.java:796) at android.os.AsyncTask$3.call(AsyncTask.java:394) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:923) 

i try it on 'Android 11, Api30, Pixel 2(or3) ' in emulator and 'Android 11, Knox Api33, One UI3.1' in device

Maybe I'm doing something wrong( Can you help me please?

mendhak commented 2 years ago

@kollabz this looks Android 11 related as well. dir.listFiles() was returning null so this code block was throwing an exception.

I've added a check for length so it should be better now.

Do you want to try out the specific commit. If you say it's OK I could give it a tag.

implementation 'com.github.mendhak:storage-chooser:1715784d34'
kollabz commented 2 years ago

@mendhak, i have no error with 'customFilter' or 'filter' in chooser builder, but i don't see any files in the selected directory. It's empy. ( Maybe something wrong with adapter? Can you help me with it please?

i try it on 'Android 11, Api30, Pixel 2(or3) ' in emulator and 'Android 11, Knox Api33, One UI3.1' in device. on 'Android 9, Api28 ' in device it work good

mendhak commented 2 years ago

@kollabz two things I can think of. First is obviously you'll want to make sure there are some files that match the filter, obviously. Second is you'll need to make sure your app has permissions, see here. One thing I noticed, despite permissions, I couldn't filter anything under /emulated/0/Android/data where all the app specific files are. I could play around at the top level like /emulated/0/Documents.

Anyway I did a test I filtered to show just "csv" files and I was get this. You can see I copied your code minus the withActivity and withContent. I tried on Android 11 and 12.

image