FileOpenPicker 在从磁贴而不是 Windows Phone 8.1 应用程序中的按钮启动访问被拒绝时会引发
本文关键字:启动 访问 按钮 拒绝 应用程序 Phone Windows FileOpenPicker | 更新日期: 2023-09-27 18:34:43
我正在尝试使用FileOpenPicker API,方法是从Windows Phone 8.1中的固定磁贴启动它。
磁贴中存储了一个命令,应用程序在从该磁贴启动时将启动 FileOpenPicker。在这种情况下,FileOpenPicker API 会引发E_ACCESSDENIED异常。从应用程序中的按钮调用相同的代码时,它不会崩溃。因此,设置为应用程序的功能还可以,只是似乎调用FileOpenPicker的环境不同。
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
openPicker.PickSingleFileAndContinue();
最后一行是从磁贴开始时崩溃的内容。在构造主页后,这两种方案都会在主页中调用它。磁贴像这样调用它,来自 App.xaml.cs/OnLaunched((:
if (!e.TileId.Equals("App"))
{
var mainPage = rootFrame.Content as Views.MainPage;
if (mainPage != null)
{
string command = e.Arguments;
if (!string.IsNullOrWhiteSpace(command) && command.Equals(Utils.TileCommand))
{
mainPage.TakePicture ();
}
}
//else
//{
// rootFrame.Navigate(typeof(Views.MainPage), e.Arguments);
//}
}
我也尝试了else部分(注释掉(并在MainPage.NavigatedTo((中调用TakePicture((方法,但同样的事情发生了。
可能是什么问题?
我不
精通Windows Phone 8.1应用程序,但您的FileOpenPicker应该异步运行UI线程。
您是否尝试过使用异步方法,如下所示?
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
可能是rootFrame是空的,或者它的内容是空的。检查 OnLaunch 方法中的 rootFrame 是否为空或内容是否为空。这可能是问题。