The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
How to Load File (pdf,jpg,etc) from HoloLens App
I'm new in the world of app development with HoloLens and with UWP apps in general. I have basic training of C# and Unity, and started to know how works HoloLens in general.
I'm currently trying to develop a simple UI 2D app. The idea is to have 4 buttons which each of them opens a predefined file (pdf, jpg, etc).
The "app" works perfectly in Unity (I wrote a very simple script where a method called OpenURL opens a file with Applications.OpenURL). However, when I deploy it in the HoloLens it doesn't work - More specifically, The app crashes when I press any button.
At first, I thought that the reason may be that the HoloLens is trying to access a local path that it doesn't exist anymore in the HoloLens (The path C:/Users/... would not make sense in the HoloLens). I tried to use the Application.addPath to fix the issue (https://docs.unity3d.com/Manual/StreamingAssets.html) but it didn't work either.
After going in depth with this problem on Internet, I noticed that there are currently two ways of doing this:
- Azure Microsoft
The problem is that there's not much information about how to develop the coding or the steps that should be followed to do this. I tried to find coding about this but I still haven't found anything yet.
I wanted to ask the community if someone has developed an app that loads files directly from a local server or from other environments. In that case, would be possible to have some sort of explanation about how to do it?
I would very much appreciate your help since I have been some sort of frustrated with this. Also, I noticed this a persistent issue for many developers; so this could be a great way to definitely sort it out and close the topic
Thanks in advance!
Your current approach will probably not work. Application.OpenURL is actually suspending your Unity app and opens the given URL in the system default webbrowser (could be Edge, Chrome, Firefox...) and brings it to the front.
If I get you right, your goal is to load a remote resource (like a jpeg image) and display it inside the HoloLens Unity app.
In this case:
1. Take look at the WWW class in the Unity scripting API
It comes with a simple but effective code example that loads a remote jpeg file and applies it to the texture of the material of a given GameObject.
Make sure to set the correct Capabilites for HoloLens in the Player Settings: At least InternetClient is needed for this to work
For Unity versions prior to 2018.2? there has been a bug when building with IL2CPP backend that prevented webrequests to work. Make sure to use .Net as scripting backend or use the most recent Unity Version
One Last advice: For great UI/UX examples for HoloLens, check out the MixedRealityToolkit. It comes with lots of examples and prefabs like Buttons and Interactables that will instantly boost your development and gives your users an awesome experience.
Thank you very much for the help. I'm currently facing other issues regarding the access of the files in a Web Server (made with Azure), but I this this option would work as soon as I fix the problem.
I also wanted to ask if the pdf file would open the same way as a jpg file, or if is need to do something else.