Skip to content

Missing .txt files in VR #103

Closed
Closed
@GabyShamblin

Description

@GabyShamblin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions