[英]Moving to forms in Windows Phone 8.1 throws “Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))”
[英]FileOpenPicker throws access denied exception when starting it from a tile rather than a button in Windows Phone 8.1 application
我試圖通過從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();
最后一行是從圖塊開始時崩潰的原因。 構造完后,這兩種方案都在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()方法,但是發生了同樣的情況。
可能是什么問題呢?
我不熟悉Windows Phone 8.1應用程序,但您的FileOpenPicker應該與UI線程異步運行。
您是否嘗試過如下使用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();
好吧,可能是rootFrame為null或它的內容為null。在OnLaunched方法中檢查rootFrame為null或content為null。 可能是個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.