yasirkula / UnitySimpleFileBrowser

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

file save/load pathes cannot be used on android 13 #72

Closed thmasn closed 2 years ago

thmasn commented 2 years ago

Description of the bug

Loading / Saving a file on Android 13 does not work. reasons seems to be unescaped characters in the file path that the fileBrowser returns. the same code works well on mac and windows.

Reproduction steps

Use the file browser, p.e. via code like this:

using System.IO;

    ...

    //like in the example code
    IEnumerator ShowLoadDialogCoroutine()
    {
        yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.FilesAndFolders, true, null, null, "Load Files and Folders", "Load");
        if (FileBrowser.Success){
            string path =FileBrowser.Result[0] ;// this will be something like p.e. content://com.android.externalstorage.documents/tree/primary%3ADocuments/document/primary%3ADocuments%2Fdom.chunk

            Debug.Log(File.Exists(path)); // logs false into the console.
        }
    }

i tried to track down the issue in the code, and it seems like the path already contains the unescaped characters in the FileBrowserHelpers.cs, where the string rawURI is extracted from the string resultRaw. so it might be, that these strings will have to be handled as they are received.

Platform specs

Additional info

Logcat (Android) warnings thrown by the file browser:

2022/09/29 20:01:13.180 13691 13716 Warn DocumentFile Failed query: java.lang.SecurityException: Document primary: is not a descendant of primary:Documents
2022/09/29 20:01:13.182 13691 13716 Warn DocumentFile Failed query: java.lang.SecurityException: Document primary: is not a descendant of primary:Documents
2022/09/29 20:01:13.184 13691 13716 Warn DocumentFile Failed query: java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3A from pid=13691, uid=10322 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
thmasn commented 2 years ago

never mind, using the FileBrowserHelper.FileExists, instead of IO.File.Exists works just fine