0

我正在尝试通过从 Windows Phone 8.1 中的固定磁贴启动 FileOpenPicker API 来使用它。

磁贴中存储了一个命令,应用程序将从该磁贴启动时启动 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(); 

最后一行是从 tile 开始时崩溃的内容。在 MainPage 构建之后,这两种情况都会在 MainPage 中调用它。磁贴从 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() 方法,但同样的情况发生了。

可能是什么问题呢?

4

2 回答 2

0

那么它可能是 rootFrame 为 null 或其内容为 null.. 检查 rootFrame 是否为 null 或 onLaunched 方法中的内容是否为 null。这可能是个问题。

于 2016-02-19T11:12:52.320 回答
0

我不熟悉 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();
于 2016-02-18T10:45:45.213 回答