Skip to content

Missing .txt files in VR #103

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

Closed
GabyShamblin opened this issue Jan 20, 2025 · 4 comments
Closed

Missing .txt files in VR #103

GabyShamblin opened this issue Jan 20, 2025 · 4 comments

Comments

@GabyShamblin
Copy link

GabyShamblin commented Jan 20, 2025

I am attempting to have a user select a folder that contains four files: two video (.avi) and two text (.txt). The strange thing is I am able to see the video files, but the its as if the text files don't exist. Selecting the folder only reads the video files.

Here is a shortened version of my code:

//! Get file permissions from Android
  void Awake() {
    #if !UNITY_EDITOR && UNITY_ANDROID
    GetExternalReadPermission();  
    #endif
  }

  private void GetExternalReadPermission()  
  {  
    GetPermission(Permission.ExternalStorageRead);  
  }  
  
  private static void GetExternalWritePermission()  
  {  
    GetPermission(Permission.ExternalStorageWrite);  
  }  
  
  private static void GetPermission(string permission)  
  {  
    if (Permission.HasUserAuthorizedPermission(permission)) {  
      Debug.Log("Permission is already granted.");  
      return;
    }  

    Debug.LogFormat("Requesting permission to {0}.", permission);  
    Permission.RequestUserPermission(permission);  
  }  



  //! Import data 
  void Start()
  {
    FileBrowser.SetFilters( true, new FileBrowser.Filter( "Video", ".mp4", ".avi" ), new FileBrowser.Filter( "Text", ".txt"));
    TestBrowser();
  }

  // Test viewing files
  public void TestBrowser() {
    using var envClass = new UnityEngine.AndroidJavaClass("android.os.Environment");
    using var docsDir = envClass.CallStatic<UnityEngine.AndroidJavaObject>("getExternalStoragePublicDirectory", "Documents");
    var docsPath = docsDir.Call<string>("getAbsolutePath");

    FileBrowser.ShowLoadDialog( 
      OnSuccess,        // Success
      OpenFileBrowser,  // Canceled
      FileBrowser.PickMode.Files, // Pick mode
      false, 				    // Multiple selection
      docsPath,             // Initial path
      null, 				    // Initial filename
      "Select Folder",  // Title
      "Select"          // Submit button
    ); 
  }

  //! Activate the file browser 
  public void OpenFileBrowser() {
    using var envClass = new UnityEngine.AndroidJavaClass("android.os.Environment");
    using var docsDir = envClass.CallStatic<UnityEngine.AndroidJavaObject>("getExternalStoragePublicDirectory", "Documents");
    var docsPath = docsDir.Call<string>("getAbsolutePath");

    FileBrowser.ShowLoadDialog( 
      OnSuccess, 		    // Success
      OpenFileBrowser, // Canceled
      FileBrowser.PickMode.Folders, // Pick mode
      false, 				    // Multiple selection
      docsPath,             // Initial path
      null, 				    // Initial filename
      "Select Folder",  // Title
      "Select"          // Submit button
    ); 
  }

  //! When file browser finishes, read through files in the folder
  void OnSuccess( string[] filePaths ) {
    // Get all selected files
    folder = filePaths[0];

    // Get files in selected folder
    string[] files = Directory.GetFiles(folder);
    // Files only contained videos!!! ^^^
  }

Image
Image

  • Unity version: 2022.3.7f1
  • Platform: Android
  • Device: Meta Quest 3
  • How did you download the plugin: Package Manager
@yasirkula
Copy link
Owner

You can try these solutions in the given order:

  1. File Access does not work on quest 2 #87 (comment)
  2. Hit Browse... button and select the Documents folder via that popup
  3. GLB and JSON files not appearing Quest Pro #89 (comment) (requires MANAGE_EXTERNAL_STORAGE permission which may not be allowed if you'll be publishing on a store)

@GabyShamblin
Copy link
Author

  1. This gave me "Primary Drive" in place of "Browse..." and made no change.
  2. I am able to get to the popup, but when submitting to try and get access to the folder, the app goes black and no change is made.
  3. This gives me a separate popup to give full permission to the app to access files, but I am unable to click the toggle. I check app permissions and my app is allowed to access files so I'm not sure why this option is being blocked.

@yasirkula
Copy link
Owner

yasirkula commented Jan 21, 2025

For 3, you may need to declare the permission in AndroidManifest: android.permission.MANAGE_EXTERNAL_STORAGE. I believe what you're seeing in app permissions was READ_EXTERNAL_STORAGE.

@GabyShamblin
Copy link
Author

That worked! Thank you.

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

No branches or pull requests

2 participants