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

Loading a file from OneDrive on Hololens

I'd like to open a file from OneDrive in my Unity Hololens app. I use FileOpenPicker.
However, the statement
StorageFile file = await openPicker.PickSingleFileAsync();
doesn't open the file picker nor does it generate an error?

Has anyone got this to work with Hololens?

Answers

  • Options

    The application crashes when I execute the above statement.

  • Options

    Using Unity + OneDrive Important

    I would second this question - am currently saving user files in Application.persistentDataPath which is the recommended place, but which of course is largely hidden from the user, and not available on the cloud.

    User Experience - Where is the stuff I am working on?

    In my application, the user will need to reuse the results across many sessions, and have an idea on other devices how their data is evolving. So putting everything in the local memory hole called Application.persistentDataPath is not the answer.

    HoloToolkit for Unity Example?

    I think this is a very common development case, providing user-visible persistent storage. A good place for a baseline would be HoloToolkit/Utilities.

  • Options
    edited August 2016

    I found a partial solution to this issue. Currently I'm using One Drive and I'm able to pull files into a Unity application at runtime. Since it's using contracts this should work equally well with any other file provider - even custom file providers. It might be possible to access certain folders using this method and enumerate the files that way, but currently I don't believe there is a generic solution for browsing a users files ala File Explorer on Windows. Doing so would at least allow users to open some files without exiting the running application.

    Step 1: Add some file associations using the Unity player settings for WSA tab. In this screen cap I'm using the 'object' file extension.

    Step 2: Build the application using XAML build type

    Step 3: Add launch files to the future access list within the generated UWP VS project. Add the following lines to OnFileActivated(...) in App.xaml.cs:

                foreach (IStorageItem item in args.Files)
                    StorageApplicationPermissions.FutureAccessList.Add(item);
    

    Step 4: Load the files in Unity. Here is the method I'm currently using the read in the entirety of the file contents:

        public delegate void ReadFileOperationCompletionAction(byte[] data, string error);
        ReadFileOperationCompletionAction completionAction;
    
        private async void ReadFileAsync(string path)
        {
            StorageFile file = await StorageFile.GetFileFromPathAsync(path);
            if (file == null)
            {
                completionAction.Invoke(null, "Could not get file from path: " + path);
                return;
            }
    
            byte[] fileData = null;
            using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
            {
                fileData = new byte[stream.Size];
                using (DataReader reader = new DataReader(stream))
                {
                    await reader.LoadAsync((uint)stream.Size);
                    reader.ReadBytes(fileData);
                }
            }
    
            if (fileData == null)
            {
                completionAction.Invoke(null, "Could not read file");
                return;
            }
    
            if (completionAction != null)
                completionAction.Invoke(fileData, null);
        }
    

    It would be nice to find a way to do this without modifying the boiler plate (it might be possible to modify the template itself). I tend to build my Unity project out to separate folders for different targets and I've already made the mistake of forgetting to touch the boiler plate. Without adding the files to the future access list the ReadFileAsync method will report that it is unable to open the file contents.

  • Options

    @psi said:
    The application crashes when I execute the above statement.

    I've got the same situation here. Do you have any solution yet?

Sign In or Register to comment.