0

I'm trying to use the FileOpenPicker API by starting it from a pinned tile in Windows Phone 8.1.

The tile has a command stored in it for which the application would start the FileOpenPicker when launched from that tile. In this case the FileOpenPicker API throws an E_ACCESSDENIED exception. 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 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. The tile calls it like this, from 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.

What could be the problem?

robcsi
  • 264
  • 3
  • 17

2 Answers2

0

I'm not versed into Windows Phone 8.1 apps but your FileOpenPicker should run asynchronously of the UI thread.

Have you tried to use the async method as following ?

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
  • 16
  • 2
  • Thanks for the input, SebD, but Studio says: "warning CS0618: 'FileOpenPicker.PickSingleFileAsync()' is obsolete: 'PickSingleFileAsync will be unavailable for Windows Phone 8.1. Instead, use PickSingleFileAndContinue'". – robcsi Feb 18 '16 at 19:10
0

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. It could be issue.

Rohit
  • 552
  • 3
  • 15
  • Rohit, there is no problem with the rootFrame, the exception is thrown on line openPicker.PickSingleFileAndContinue();. Thanks for the input. – robcsi Feb 21 '16 at 09:34