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

File Access does not work on quest 2 #87

Closed
thmasn opened this issue Sep 12, 2023 · 5 comments
Closed

File Access does not work on quest 2 #87

thmasn opened this issue Sep 12, 2023 · 5 comments
Labels

Comments

@thmasn
Copy link

thmasn commented Sep 12, 2023

it seems to be i am the first one trying to use the file browser on a quest 2!

Description of the bug

File Access on the quest 2 seems to be limited to the apllications own folder.
everything works perfectly in the application folder which is opened by default.
but, even after granting rights to another folder to the application, only the application folder is shown. no new quick links appear on the left side of the file browser, no other files are visible in the right side item view.

Reproduction steps

  • use file browser package
  • small adjustments for vr ui etc.
  • verify it is working well on android, no issues on an android smartphone
  • deploy to quest 2
  • try to follow the same steps as we did earlier on a android smartphone
  • unable to select a new folder location
    video showing what happens

Platform specs

  • Unity version: 2021.3.29f1 on Windows

  • Device: "Quest 2 version 56"

  • How did you download the plugin: GitHub, latest version as of today

Additional info

no errors in logcat. i did add custom debug logs, which tell me:
in FetchPersistedSAFQuickLinks(), resultRaw is always "0", which causes the function to return.
my guess is that this is the cause of no quick links appearing. why is it zero? i do not know...

@thmasn thmasn added the bug label Sep 12, 2023
@yasirkula
Copy link
Owner

Can you try running this code in Awake/Start:

#if !UNITY_EDITOR && UNITY_ANDROID
typeof(SimpleFileBrowser.FileBrowserHelpers).GetField("m_shouldUseSAF", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, (bool?)false);
#endif

@thmasn
Copy link
Author

thmasn commented Sep 13, 2023

i had to add
"using System.Reflection;"
and added the code to the beginning of Awake()

now it works perfectly, i can even see all the folders on the device!

i have no idea why it works, but thank you a lot for the help!

@yasirkula
Copy link
Owner

yasirkula commented Sep 13, 2023

You're welcome. I don't know why it works either, I've just stopped asking myself this question some time ago 🙈

@raisazf
Copy link

raisazf commented Aug 29, 2024

Hello Thmasn, I'm trying to adopt the browser to work on Quest Pro to access files on my PC, rather than Assets only. I tried following steps above but since I'm new to Unity, I think I'm doing something wrong. Could you please provide me with more information how you fixed the issue, i.e., which files had to be updated and how. Also, my controllers do not interact with the browser, while I'm not having any issues with other objects in the scene. Any hints why? Thanks so much in advance!

@elyeskacem
Copy link

Hello Thmasn, I'm trying to adopt the browser to work on Quest Pro to access files on my PC, rather than Assets only. I tried following steps above but since I'm new to Unity, I think I'm doing something wrong. Could you please provide me with more information how you fixed the issue, i.e., which files had to be updated and how. Also, my controllers do not interact with the browser, while I'm not having any issues with other objects in the scene. Any hints why? Thanks so much in advance!

The default prefab of the UI is a canvas that has a camera screen space - overlay as Render Mode, You need to change that into world space, and you need to make some other tasks as adding surface to the canvas and adding the other scripts , you can follow this link it may help you.

After applying the necessary modification on the prefab, you need to adapt the instantiation of that prefab in the script FileBrowser.cs ( in my case , I had to change the line 358 , I need to get the component FileBrowser to m_instance variable )

And finally, you can test all that using this script :
`using UnityEngine;
using System.Collections;
using System.IO;
using SimpleFileBrowser;
using System.Reflection;

public class FileBrowserTest : MonoBehaviour
{
// Warning: paths returned by FileBrowser dialogs do not contain a trailing '' character
// Warning: FileBrowser can only show 1 dialog at a time

private void Awake()
{
    #if !UNITY_EDITOR && UNITY_ANDROID
    typeof(SimpleFileBrowser.FileBrowserHelpers).GetField("m_shouldUseSAF", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, (bool?)false);
    #endif
}

void Start()
{
    // Set filters (optional)
    // It is sufficient to set the filters just once (instead of each time before showing the file browser dialog),
    // if all the dialogs will be using the same filters
    FileBrowser.SetFilters(true, new FileBrowser.Filter("Images", ".jpg", ".png"), new FileBrowser.Filter("Text Files", ".txt", ".pdf"));

    // Set default filter that is selected when the dialog is shown (optional)
    // Returns true if the default filter is set successfully
    // In this case, set Images filter as the default filter
    FileBrowser.SetDefaultFilter(".pdf");

    // Set excluded file extensions (optional) (by default, .lnk and .tmp extensions are excluded)
    // Note that when you use this function, .lnk and .tmp extensions will no longer be
    // excluded unless you explicitly add them as parameters to the function
    FileBrowser.SetExcludedExtensions(".lnk", ".tmp", ".zip", ".rar", ".exe");

    // Add a new quick link to the browser (optional) (returns true if quick link is added successfully)
    // It is sufficient to add a quick link just once
    // Name: Users
    // Path: C:\Users
    // Icon: default (folder icon)
    FileBrowser.AddQuickLink("Users", "C:\\Users", null);

    // !!! Uncomment any of the examples below to show the file browser !!!

    // Example 1: Show a save file dialog using callback approach
    // onSuccess event: not registered (which means this dialog is pretty useless)
    // onCancel event: not registered
    // Save file/folder: file, Allow multiple selection: false
    // Initial path: "C:\", Initial filename: "Screenshot.png"
    // Title: "Save As", Submit button text: "Save"
    // FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" );

    // Example 2: Show a select folder dialog using callback approach
    // onSuccess event: print the selected folder's path
    // onCancel event: print "Canceled"
    // Load file/folder: folder, Allow multiple selection: false
    // Initial path: default (Documents), Initial filename: empty
    // Title: "Select Folder", Submit button text: "Select"
    // FileBrowser.ShowLoadDialog( ( paths ) => { Debug.Log( "Selected: " + paths[0] ); },
    //                         () => { Debug.Log( "Canceled" ); },
    //                         FileBrowser.PickMode.Folders, false, null, null, "Select Folder", "Select" );

    // Example 3: Show a select file dialog using coroutine approach
    StartCoroutine(ShowLoadDialogCoroutine());
}

IEnumerator ShowLoadDialogCoroutine()
{
    // Show a load file dialog and wait for a response from user
    // Load file/folder: file, Allow multiple selection: true
    // Initial path: default (Documents), Initial filename: empty
    // Title: "Load File", Submit button text: "Load"
    yield return FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, true, null, null, "Select Files", "Load");

    // Dialog is closed
    // Print whether the user has selected some files or cancelled the operation (FileBrowser.Success)
    Debug.Log(FileBrowser.Success);

    if (FileBrowser.Success)
        OnFilesSelected(FileBrowser.Result); // FileBrowser.Result is null, if FileBrowser.Success is false
}

void OnFilesSelected(string[] filePaths)
{
    // Print paths of the selected files
    for (int i = 0; i < filePaths.Length; i++)
        Debug.Log(filePaths[i]);

    // Get the file path of the first selected file
    string filePath = filePaths[0];

    // Read the bytes of the first file via FileBrowserHelpers
    // Contrary to File.ReadAllBytes, this function works on Android 10+, as well
    byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(filePath);

    // Or, copy the first file to persistentDataPath
    string destinationPath = Path.Combine(Application.persistentDataPath, FileBrowserHelpers.GetFilename(filePath));
    FileBrowserHelpers.CopyFile(filePath, destinationPath);
}

}
`

I hope that I helped you,

Happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants