简体   繁体   English

Unity UWP FolderPicker引发无效的窗口句柄异常

[英]Unity UWP FolderPicker Throws Invalid Window Handle Exception

I'm getting the above exception when trying to user the FolderPicker in a UWP Unity App. 尝试在UWP Unity应用程序中使用FolderPicker时,出现上述异常。 I have copied the code from a working example but having no success: 我已经从一个有效的示例复制了代码,但没有成功:

FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
try
{
    StorageFolder folder = folderPicker.PickSingleFolderAsync().GetResults();
}
catch (Exception e)
{
    Debug.Log(e.ToString());
}

My assumption is that it doesn't work with Unity UWP, in a similar vein to Unity offering a subset of .NET etc. Can anyone confirm this or am I missing something obvious? 我的假设是,它不能与Unity UWP一起使用,类似于Unity提供.NET等的子集。有人可以确认这一点吗?或者我缺少明显的东西吗?

Best, Peter 最好,彼得

Have you added the capabilities and declarations needed for accessing the files from a folder? 您是否添加了从文件夹访问文件所需的功能和声明? This may be the reason for the above error. 这可能是上述错误的原因。

To pick files from folder you need to select Pictures Library from Capabilities. 要从文件夹中选择文件,您需要从功能中选择图片库。 Also under declarations add File Open Picker. 同样在声明下添加文件打开选择器。

You can find this options in Package.appxmanifest. 您可以在Package.appxmanifest中找到此选项。

Check this for accessing the file from the folder. 选中此选项可从文件夹访问文件。

https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions https://docs.microsoft.com/zh-cn/windows/uwp/files/file-access-permissions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM