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

getDirectoryPath() doesn't work in example app on Android 11 (OnePlus) #745

Closed
1 of 4 tasks
redsolver opened this issue Jun 14, 2021 · 16 comments · Fixed by #763
Closed
1 of 4 tasks

getDirectoryPath() doesn't work in example app on Android 11 (OnePlus) #745

redsolver opened this issue Jun 14, 2021 · 16 comments · Fixed by #763
Labels
android Issue applies to Android platform bug Something isn't working

Comments

@redsolver
Copy link
Contributor

Describe the bug

  • Run the example app with flutter run --release on Android 11 (OnePlus in my case)
  • Try to pick a directory using the "Pick folder" button in the example app
    -> Always returns an empty path (/) even for unprotected directories

When changing the targetSdkVersion to 29 in example/android/app/build.gradle, the bug disappears

Platform

  • Android
  • iOS
  • Web
  • Desktop (Go)

Platform OS version
Android 11 (OnePlus)

How are you picking?
FilePicker.platform.getDirectoryPath() in the example app

Details to reproduce the issue

  • Use Android 11 (maybe only OnePlus is affected)
  • Run the example app with flutter run --release
  • Try to pick a directory using the "Pick folder" button in the example app

Flutter Version details

[✓] Flutter (Channel stable, 2.2.2, on Linux, locale de_DE.UTF-8)
    • Flutter version 2.2.2 at /home/redsolver/dev/flutter
    • Framework revision d79295af24 (vor 3 Tagen), 2021-06-11 08:56:01 -0700
    • Engine revision 91c9fc8fe0
    • Dart version 2.13.3

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/redsolver/Android/Sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+0-b944-P17168821)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Connected device (3 available)
    • GM1913 (mobile) • <removed id> • android-arm64  • Android 11 (API 30)
    ```
@redsolver redsolver added the new issue An issue that hasn't yet been seen from the maintainer label Jun 14, 2021
@algoexpt
Copy link

There are a number of similar issues reported which the author suspects is due to 'special directories' but that's not the case.

I found that getPath() is used in FileUtils.java, which in Android 11 is blocked and getDirectory() is suggested instead. See this link:
https://developer.android.com/about/versions/11/non-sdk-11

@miguelpruivo can you try changing getPath to getDirectory? Hope this works!

@miguelpruivo
Copy link
Owner

@algoexpt just tried it without success. Although I can confirm that using SDK 30 prevents me immediately from selecting invalid folders like shown in the screenshot.
Captura de ecrã 2021-06-22, às 15 28 38

@Richard2823
Copy link

Can confirm this does not work on Android 11 (just returns "/"). Hope it gets fixed.

@tomm1e
Copy link
Contributor

tomm1e commented Jul 5, 2021

getDirectory works for all media directories, except Downloads root and storage roots are not allowed.
I tested the PR on 11 emulator with target SDK 30. Not sure if it needs a fallback for earlier versions.

I tried granting the app with ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION but it still didn't allow selecting storage roots

@spacekestrel
Copy link

Same here.

@miguelpruivo
Copy link
Owner

@tomm1e does that work for previous versions?

@bluntmess
Copy link

Hello, any update on this? I'm also facing this issue.
logs:

D/FilePickerDelegate( 8136): [SingleFilePick] File URI:content://com.android.externalstorage.documents/tree/primary%3ATest/document/primary%3ATest
W/aster_null_saf( 8136): Accessing hidden method Landroid/os/storage/StorageVolume;->getPath()Ljava/lang/String; (greylist-max-q,test-api, reflection, denied)
I/flutter ( 8136): result: /

Device - Android 11 Emulator
build.gradle config: minSdkVersion 21 , targetSdkVersion 30

@bluntmess
Copy link

@tomm1e does that work for previous versions?

I just checked the pull request changes on android 10 and found that it didn't work.

It did work completely in android 11, even for folders inside downloads.

@miguelpruivo
Copy link
Owner

@brightseagit and does the current version work on Android 10 for you? If so, I may add a version check to make it backwards compatible before merging.

@miguelpruivo miguelpruivo added android Issue applies to Android platform bug Something isn't working and removed new issue An issue that hasn't yet been seen from the maintainer labels Jul 20, 2021
@bluntmess
Copy link

@brightseagit and does the current version work on Android 10 for you? If so, I may add a version check to make it backwards compatible before merging.

Hello,
I just checked and found that the current version is working fine on my android 10 device . I also created a folder in downloads and got the correct location of the folder.

So, yes the old version works fine on android 10. And it would be great if you could add the version check to make it backwards compatible.

Thank you.

@tomm1e
Copy link
Contributor

tomm1e commented Jul 20, 2021

@brightseagit Test #763 again I added the fallback.

@bluntmess
Copy link

@brightseagit Test #763 again I added the fallback.

I just checked and found that it is working on android 10 and 11. But in android 10 I noticed that it gives / when choosing a folder inside downloads directly. And when I choose that folder like this storage>downloads>folder I get the correct path.

@miguelpruivo
Copy link
Owner

@brightseagit this little nuances and differences across multiple SDK make it really tough to create a reliable API for this. 😞

Anyway, I think that this might be the best we have as of now.

@bluntmess
Copy link

@miguelpruivo yes I 💯% agree with that 👍.

@miguelpruivo
Copy link
Owner

Just deployed a new version (3.0.4) with a fix for this. Thank you @tomm1e for the effort.

@alexaniko88
Copy link

If you update this library to 3.0.4 and your Android targetSdkVersion and compileSdkVersion points to 29, compilation will fail.
Be sure that is increased at least to 30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issue applies to Android platform bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants