yasirkula / UnitySimpleFileBrowser

A uGUI based runtime file browser for Unity 3D (draggable and resizable)
MIT License
817 stars 111 forks source link

Android Showing Different Menu #84

Closed krishrajchal closed 11 months ago

krishrajchal commented 11 months ago

Description of the bug

When I used the plugin before, I remember being able to select files from the Internal Storage. Now, when I press the browse button, it shows "Can't use this folder, To protect your privacy, choose another folder."

I set these permissions in the manifest: READ_EXTERNAL_STORAGE WRITE_EXTERNAL_STORAGE MANAGE_EXTERNAL_STORAGE

tools:node is replace requestLegacyExternalStorage is true

Reproduction steps

Open using ShowDialog with allowMultiSelection true and PickMode to FilesAndFolders Press on browse

Platform specs

Additional info

No errors relating to the plugin or unity: libprocessgroup set_timerslack_ns write failed: Operation not permitted

yasirkula commented 11 months ago

Unfortunately, Android prevents selecting the root directory and Downloads on newer Android versions while "Browse..."ing. Overcoming it requires MANAGE_EXTERNAL_STORAGE permission being granted from Settings but unless your app is strictly a file browser app, Google Play can reject your app due to this permission.

You may also use NativeFilePicker if you're only interested in picking files (and you're picking common file types like pdf, jpg, etc.).

krishrajchal commented 11 months ago

When I was trying to make it work, I had a plugin that asked for the MANAGE_EXTERNAL_STORAGE permission. Even with permission, it still had that menu.

yasirkula commented 11 months ago

Hmm, could you set this field to false via Reflection and try again: https://github.com/yasirkula/UnitySimpleFileBrowser/blob/db6c74e751238113ca9d1d19c19c580e6628687d/Plugins/SimpleFileBrowser/Scripts/FileBrowserHelpers.cs#L80

#if !UNITY_EDITOR && UNITY_ANDROID
typeof(FileBrowserHelpers).GetField("m_shouldUseSAF", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(null, (bool?)false);
#endif
krishrajchal commented 11 months ago

Where does the reflection go?

yasirkula commented 11 months ago

Awake is a good candidate.

krishrajchal commented 11 months ago

NullReferenceException on the reflection part.

yasirkula commented 11 months ago

Did you include #if part in your code? You must, if you didn't. PS. Oh wait the field is static. You should change BindingFlags.Instance to BindingFlags.Static.

krishrajchal commented 11 months ago

Good thing it works but, there are some warnings that may prevent it from working on the Google Play Store. I will try to fix them:

Accessing hidden method Landroid/os/storage/StorageVolume;->getPath()Ljava/lang/String; (max-target-q,test-api, reflection, denied)

If this is a platform test consider enabling VMRuntime.ALLOW_TEST_API_ACCESS change id for this package.

yasirkula commented 11 months ago

Does replacing SimpleFileBrowser.aar with the one inside this zip archive resolve the issue?

krishrajchal commented 11 months ago

That worked, now, those warnings are not there and the nav button is visible too (previously not showing).