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?

2

There are 2 answers

1
SebD On

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();
1
Rohit On

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.