如何将文件保存到Hololens的Documents文件夹中? [英] How to save files to Documents folder on Hololens?

查看:641
本文介绍了如何将文件保存到Hololens的Documents文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Hololens上保存一些持久的JSON文件.他们需要在应用程序的各个版本之间保持持久性,因此Application.persistentDataPath不起作用.我选择文档"是因为它最有意义. Hololens上没有下载"文件夹.

I want to save some persistent JSON files on Hololens. They need to persist across builds of application so Application.persistentDataPath doesn't work. I chose to Documents because it makes the most sense. There is no Downloads folder on Hololens.

这是我到目前为止尝试过的:

Here's what I've tried so far:

我已阅读应用程序功能文档,并手动将<uap:Capability Name="documentsLibrary"/>添加到文件中的Package.appxmanifest.

I have read the App Capability Documentation and manually added the <uap:Capability Name="documentsLibrary"/> to the Package.appxmanifest to the file.

我还添加了xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"命名空间.但我收到以下警告:

I also added the xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" namespace. But I get the following warning:

The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities'. List of possible elements expected: 'DeviceCapability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'. Ad-Hoc Localz D:\Repositories\ad-hoc-localization\_build\Ad-Hoc Localz\Package.appxmanifest 37 

以及构建时出现以下错误:

and the following error on build:

Error APPX0501 Validation error. error C00CE014: App manifest validation error: The app manifest must be valid as per schema: Line 45, Column 6, Reason: Element '{http://schemas.microsoft.com/appx/manifest/uap/windows10}Capability' is unexpected according to content model of parent element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Capabilities'. Expecting: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}DeviceCapability. Ad-Hoc Localz D:\Repositories\ad-hoc-localization_build\build\bin\Win32\Master\AppxManifest.xml 1 

它还说我需要指定我使用的文件类型图像中从

It also says that I need to specify file type I used this documentation to add that manually to manifest. But I get the same warning i.e. invalid child element. I do not see a GUI based way to add like in this image from this forum

那我该如何构建一个可以访问Hololens上的Documents文件夹的应用程序?

在代码中,我使用Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)来获取文档的路径,但是在代码段中,它们表明应该为KnownFolders.DocumentsLibrary. UWP上的Environment无效名称空间吗?

In the code I'm using Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) to get path to documents but in code snippet they show that it should be KnownFolders.DocumentsLibrary. Is the Environment not valid namespace on UWP?

链接到整个清单.

推荐答案

  1. 不使用

xmlns:rescap =""http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"因为DocumentLibrary功能在uap命名空间中.如下添加文档功能

xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" because DocumentLibrary capability is in uap namespace. add document capability like below

<Capabilities>  
    <Capability Name="internetClientServer"/>
   <Capability Name="internetClient"/>
   <uap:Capability Name="documentsLibrary"/>
  <DeviceCapability Name="microphone"/>  
</Capabilities>

现在您不应该得到警告.

now you should not get warning.

  1. 使用下面的代码行在Document文件夹中创建和获取文件

  1. Use below lines of code to create and get file in Document folder

 IReadOnlyList<Windows.Storage.StorageFile> 
 file=awaitKnownFolders.DocumentsLibrary.CreateFileAsync("FileName");

 IReadOnlyList<Windows.Storage.StorageFile> 
 file=awaitKnownFolders.DocumentsLibrary.GetFileAsync("filename")

这篇关于如何将文件保存到Hololens的Documents文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆