cancel
Showing results for 
Search instead for 
Did you mean: 

Loading image from Quest's sd card

Anonymous
Not applicable
Hi fellow devs,

I am working on Unity 2019 with a Quest device
I am trying to load an image from the quest's sd card to my application but I don't really know what to do.

I tried an unity plug-in which is able to call the native gallery on android device but it doesn't work on quest.
I tried an unity plug-in which is able to open an Unity's OnGUI File browser but it also doesn't work on quest.
I thought I could try to call the oculus gallery application by intent, but I didn't find the documentation of the application.

So I don't know what I can try else. Anybody has an idea ?

Edit :
Sorry I just saw that I am in the wrong part of the forum ^^
I can't find how to switch to Oculus Quest Development
2 REPLIES 2

RecoveryVR
Protege
Hey I've been having trouble with loading stuff from the sdcard myself but it's resolved now! Check out https://forums.oculusvr.com/developer/discussion/78412/accessing-local-files#latest

shpOculus84
Honored Guest
I had been looking around for a solution to accomplish this, and now I can share my code expecting to this solution can help to you on your projects. Also, take the next considerations:

* Turn on external persmissions to read and write from your app (via android manifest on Unity, oculus quest app config or via Side Quest config).
* Change write permission to external on Unity (Project Settings -> Player -> Other Settings -> Write Permission -> External (SD Card)
* When your app is installed on your device, put your stuff on the root or subfolders on: \Quest (...your device...) \Internal shared storage\Android\data\com.YourCompany.YourApp\files   (be careful with the slashes and where you looking for  under your device and your app package name as com.YourCompany.YourApp in this case).
* TURN OFF your device and then turn it on. It could happen that the url doesn't update succefully until you turn it off and on, and not only rebooting it).
* Verify your game objects components are available to render. For example, I didn't notice at the begining that I was letting my Game Object within the image component outside the Canvas, so the camera wasn't "seeing it". This can happen with any other kind of component, for example, if there isnt the video component configured or some audiosource, audiolistener, etcetera. 
* Verify your url strings and slashes.


CODE:

  public Image myImage01; // My Unity Game Object and component to render the source
  public TextMeshPro urlLabel; // To debug my url on the device

    public void Awake()
    {  
        myImage01.GetComponent<Image>().sprite = LoadSprite(Application.persistentDataPath + "/IMAGE.jpg");  
    }
    private Sprite LoadSprite(string path)
    {
        urlLabel.text = path;
        if (string.IsNullOrEmpty(path)) return null;
        if (System.IO.File.Exists(path))
        {
            byte[] bytes = System.IO.File.ReadAllBytes(path);
            Texture2D texture = new Texture2D(1, 1);
            texture.LoadImage(bytes);
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            return sprite;
        }
        return null;
    }