【问题标题】:FileOpenPicker throws access denied exception when starting it from a tile rather than a button in Windows Phone 8.1 applicationFileOpenPicker 在 Windows Phone 8.1 应用程序中从磁贴而不是按钮启动时抛出拒绝访问异常
【发布时间】:2016-02-16 10:59:16
【问题描述】:

我正在尝试通过从 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() 方法,但同样的情况发生了。

可能是什么问题?

【问题讨论】:

    标签: c# windows-phone-8.1 fileopenpicker


    【解决方案1】:

    我不熟悉 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();
    

    【讨论】:

    • 感谢 SebD 的输入,但 Studio 说:“警告 CS0618:'FileOpenPicker.PickSingleFileAsync()' 已过时:'PickSingleFileAsync 将无法用于 Windows Phone 8.1。请改用 PickSingleFileAndContinue'”。
    【解决方案2】:

    这可能是 rootFrame 为 null 或其内容为 null.. 在 OnLaunched 方法中检查 rootFrame 是否为 null 或 content 是否为 null。这可能是个问题。

    【讨论】:

    • Rohit,rootFrame没有问题,openPicker.PickSingleFileAndContinue();线上抛出异常。感谢您的意见。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    相关资源
    最近更新 更多