Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question access to oculus 2 local video/images from unity

Discussion in 'VR' started by RedSkyLine, May 10, 2023.

  1. RedSkyLine

    RedSkyLine

    Joined:
    Nov 30, 2020
    Posts:
    2
    hello, i want to ask how can i access to some videos and image url which are located in my oculus 2 local storage to use them in unity, i used to access by url /sdcard/Android/../../...mp4 but its not working anymore
     
  2. CMaster_Thomas

    CMaster_Thomas

    Joined:
    Jan 13, 2020
    Posts:
    5
    having the same issue at the moment, worked fine before
     
  3. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    510
    This is because the Quest OS v53 now uses Android 12, which limits the way apps can access storage. From the developers of Polysketch:

    - No Access
    --- /sdcard/Polysketch/
    - Can create folders, but not files
    --- /sdcard/Android/Polysketch/
    - Full folder & file creation
    --- /sdcard/Andoird/Android/data/com.PolysketchLLC.Polysketch/files (Application.persistentDataPath)
    --- /sdcard/Download/Polysketch/ ----- not very safe as users will arbitrarily delete-all here if running out of space
    --- /sdcard/Documents/Polysketch/ ----- seems like the best option. Easy user access, and we can read each other's save locations if we wish to.

    How to update -
    Setting the flag preserveLegacyExternalStorage to true in the manifest will allow you to read & write from sdcard/whatever/ if the app is installed as an update to an older version. On clean installs, this flag is ignored. So this flag won't grant us access indefinitely, but will let us read old save files and move them to the new preferred spot. AndroidManifest.xml <application android:requestLegacyExternalStorage="true" android:preserveLegacyExternalStorage="true">
     
    Jussi_FIN and mgear like this.
  4. RedSkyLine

    RedSkyLine

    Joined:
    Nov 30, 2020
    Posts:
    2
    h
    hello sir thanks for responding, I didn't quit understood how to fix it, i've added android reserveLegacyExternalStorage="true" to the manifest but I couldn"t build the project
     

    Attached Files:

  5. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    510
    My post above shows which locations are allowed to access, namely either Application.persistentDataPath, Downloads, or Documents. You can get these folders like this:

    Code (csharp):
    1. AndroidJavaObject downloadFolder = environment.CallStatic<AndroidJavaObject>("getExternalStoragePublicDirectory", environment.GetStatic<AndroidJavaObject>("DIRECTORY_DOWNLOADS"));
    2. string folderPath = downloadFolder.Call<string>("getAbsolutePath");
     
  6. EricRLee

    EricRLee

    Joined:
    Feb 4, 2020
    Posts:
    1
    I think Thomas was referring to
    Code (CSharp):
    1. android:preserveLegacyExternalStorage="true"
    while the system thought that was an emoji
     
    Thomas-Mountainborn likes this.
  7. Jussi_FIN

    Jussi_FIN

    Joined:
    Feb 10, 2021
    Posts:
    2
    Sorry for newbie question, but what's the
    environment
    in that code?

    I'm using Unity and Quest 2 and want to read a jpg picture from the persistent data path, but it won't load on Quest 2. Same code works on PC and debug messages tell that 1.jpg file is in the directory both on PC and Quest 2.

    EDIT: Man, Chat-GPT is excellent for these kind of small easy questions. I pasted those two lines and asked what's the "environment", and it explained everything, but I paste only the relevant part:
    environment: Presumably, this is an instance of AndroidJavaClass that represents the Android environment. This could be obtained by calling new AndroidJavaClass("android.os.Environment"), for example.
     
    Last edited: Oct 13, 2023