简体   繁体   English

从图块而不是从Windows Phone 8.1应用程序中的按钮启动FileOpenPicker时,引发访问被拒绝的异常

[英]FileOpenPicker throws access denied exception when starting it from a tile rather than a button in Windows Phone 8.1 application

I'm trying to use the FileOpenPicker API by starting it from a pinned tile in Windows Phone 8.1. 我试图通过从Windows Phone 8.1中的固定图块启动FileOpenPicker API来使用它。

The tile has a command stored in it for which the application would start the FileOpenPicker when launched from that tile. 磁贴中存储有一个命令,当从该磁贴启动时,应用程序将针对该命令启动FileOpenPicker。 In this case the FileOpenPicker API throws an E_ACCESSDENIED exception. 在这种情况下,FileOpenPicker API会引发E_ACCESSDENIED异常。 When calling the same code from a button in the application it doesn't crash. 从应用程序中的按钮调用相同的代码时,它不会崩溃。 So, the capabilities set to the application are ok, it just seems that the environment the FileOpenPicker is called isn't the same. 因此,为应用程序设置的功能还可以,似乎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(); 

The last line is what crashes when starting from tile. 最后一行是从图块开始时崩溃的原因。 Both scenarios call this inside the MainPage, after it's constructed. 构造完后,这两种方案都在MainPage内部调用此方法。 The tile calls it like this, from App.xaml.cs/OnLaunched(): 磁贴从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);
    //}
}

I also tried the else part (commented out) and calling the TakePicture() method in MainPage.NavigatedTo () instead, but the same happens. 我还尝试了else部分(已注释掉)并改为在MainPage.NavigatedTo()中调用TakePicture()方法,但是发生了同样的情况。

What could be the problem? 可能是什么问题呢?

I'm not versed into Windows Phone 8.1 apps but your FileOpenPicker should run asynchronously of the UI thread. 我不熟悉Windows Phone 8.1应用程序,但您的FileOpenPicker应该与UI线程异步运行。

Have you tried to use the async method as following ? 您是否尝试过如下使用async方法?

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();

Well it could be that rootFrame is null or its contents are null.. Check if rootFrame is null or content is null in OnLaunched method. 好吧,可能是rootFrame为null或它的内容为null。在OnLaunched方法中检查rootFrame为null或content为null。 It could be issue. 可能是个问题。

暂无
暂无

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

相关问题 移至Windows Phone 8.1中的表单会引发“访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))” - Moving to forms in Windows Phone 8.1 throws “Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))” 从Windows Phone 10上的FileOpenPicker访问摄像头 - Access camera from FileOpenPicker on Windows Phone 10 Windows Phone 8.1应用在使用ChatMessageManager.RequestStoreAsync()时会引发访问被拒绝 - Windows phone 8.1 app throws Access denied when using ChatMessageManager.RequestStoreAsync() 在Windows Phone 8.1中打开FileOpenPicker时出现Backbutton问题 - Backbutton issue when opened FileOpenPicker in windows phone 8.1 Windows Phone 8.1相机初始化 - 访问被拒绝的例外 - Windows Phone 8.1 Camera Initialisation - Access Denied Exception 调用Windows Phone 8.1 ContactManager.RequestStoreAsync()时,访问被拒绝异常。 - Access Denied exception when calling Windows Phone 8.1 ContactManager.RequestStoreAsync(); 访问被拒绝。 来自HRESULT的异常:Windows Phone 8.1中的0x80070005 - Access is denied. Exception from HRESULT: 0x80070005 in Windows Phone 8.1 FileOpenPicker无法使用PhoneGap运行Windows Phone 8.1 - FileOpenPicker not working windows phone 8.1 using phonegap Windows Phone 8.1-按名称过滤FileOpenPicker - Windows Phone 8.1 - FileOpenPicker filter by name Windows Phone 8.1语音合成器访问被拒绝? - Windows Phone 8.1 Speech Synthesizer Access Denied?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM