Hello everyone.

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.
Options

How to get the file when my app is opened via a file association?

Hello everyone,

I am fairly new to developing on the Hololens and have run into a snag. I am trying to make an application that is capable of viewing a 3D model file. Due to the restricted nature of the file system on the Hololens, my plan is to have the user download the file in Edge, click the downloaded file which should open my application via file associations. This part is fairly easy and I have the association in place. It opens my application just fine.

The problem is that I am using Unity and am not sure how to get the reference to the file inside of the application. I have searched and have not been able to find an example of anyone attempting this. Some of the things that I have tried include using Environment.GetCommandLineArgs() (which does not exist on the Hololens), as well as attempting to override the OnFileActivated() event (which also does not appear possible). Is there a way to accomplish this?

Regards,

Zarraya

Tagged:

Answers

  • Options
    dbarrettdbarrett ✭✭✭
    edited December 2017

    What folder are you downloading the files to?

    What I mean by that is that I would go about this a different way. Since there is no command prompt on the HoloLens there is nothing like Environment.GetCommandLineArgs() on the device or anything similar.

    The way I would go about doing something like this is loading the folder that file was saved to or something like loading the last file in the folder maybe? This will create a sort of a custom file picker and let you choose the files you want as well as view your previous files assuming they are in the same folder.

    If you say save all of these files to something like the camera roll or something. (just as an example, probably save them somewhere else). You could get the folder with something like

    StorageFolder folder = Windows.Storage.KnownFolders.CameraRoll

    An alternative to saving to a known folder is that if you have the file path of the folder/file you want to access. You can do something like:

    StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path);

    Then you can get all the files under that folder by doing something like:

    IReadOnlyList<StorageFile> sortedFiles = await folder.GetFilesAsync(CommonFileQuery.OrderByDate,0,20);

    I know this isn't exactly what you're looking for but, it could be a pretty decent workaround. Checkout the Windows.Storage namespace particularly, StorageFolder and StorageFile.

    You will also have to surround your code with if and endif statements as the editor doesn't support UWP code.

    If you do go this route you will also have to create a method surrounded by the if/endif and then create a wrapper class that calls the method in order to call it in unity without it complaining.

    if WINDOWS_UWP
    public void myWindowsmethod()
    { //do windows stuff here }
    endif

    public void myUnitymethod()
    {
    if WINDOWS_UWP
    myWindowsmethod();
    endif
    }

    AR Developer

Sign In or Register to comment.