crani
crani

Reputation: 96

Unity3D Hololens access Windows.Storage.KnownFolders

I need to access the PicturesLibrary fodler on the Hololens. Docs state that you can do that by "Windows.Storage.PicturesLibrary"

But I can not import the namespace "Windows" in my Unity project because its not included in UWP, also it should be possible. I am using the Unity3D 2019.2 with .net 4.x

How can I load pictures from the folder the right way with the HoloLens?

I tried some examples from similar questions but none of them worked, like eg.g:

#if !UNITY_EDITOR && UNITY_WINRT_10_0
return Windows.Storage.KnownFolders.PicturesLibrary.Path;                 
#else

Upvotes: 1

Views: 1547

Answers (2)

Graeme Rock
Graeme Rock

Reputation: 612

You need to wrap the import in an #if statement as well. This is what I am using for the HoloLens 2 in C#:

#if UNITY_WSA_10_0 && ENABLE_WINMD_SUPPORT
using Windows.Storage;
#endif

You will also need to ensure that the correct Capabilities are checked in the settings of the solution you are building (or wherever you build from), so the Hololens device knows what the app will try to gain access to.

In Visual Studio, the Capabiliities settingscan be found under Solution Explorer > Project > open Package.appxmanifest > Capabiliites tab.

In Unity, it is under Project Settings > Player > Publishing Settings > Capabilities.

You would select PicturesLibrary, Objects3D, or the checkbox corresponding to the folder you are attempting to access.

Unity failed to update the Package.appxmanifest in VS for me, so I had to edit it myself.


(Late answer, I know, but I hope it helps those who wander to this question!)

Upvotes: 0

HoloSheep
HoloSheep

Reputation: 53

@crani have you set the UWP App Capability declaration for PicturesLibrary access?

note that the docs mention that the capability provides access to "enumerate" the files in the library. Path is typically going to be an empty string for any of the KnowFolder types.

You will need to do something like this:

StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
IReadOnlyList<StorageFile> pictures = await picturesFolder.GetFilesAsync();

So if you wrap something similar in an #if directive you should be able to access the files, but the path is abstracted from the app as a storage folder.

Upvotes: 1

Related Questions