OpenFilePicker not working on Windows Phone 8 (Specified method is not supported)

核能气质少年 提交于 2019-11-27 08:28:22

问题


I am trying to just pick a file using:

private async void Button_Click_1(object sender, RoutedEventArgs e)
{
    try
    {
            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();
            if (file != null)
            {
                // Application now has read/write access to the picked file
                txt.Text = "Picked file: " + file.Name;
            }
            else
            {
                txt.Text = "Operation cancelled.";
            }

    }
    catch (Exception exception)
    {
        txt.Text = exception.Message;
    }
}

...but It throws an exception: `Specified method is not supported.";

I copied and pasted the code from the Windows Phone 8 docs. None of their samples work. I thought that maybe I am missing a Documents capability/Contract or whatever but they don't even exist in VS for Phone apps.

Why won't this work?

I have tracked it down to the very first line of the try:

FileOpenPicker openPicker = new FileOpenPicker(); // this is the line the exception is thrown on.

回答1:


According to the MSDN-forums and an answer from what i assume is a MS employee (here):

We do not currently support choosing files other than photos or choosing files from other Store apps.

So it looks like you are stuck with the PhotoChooserTask instead of FileOpenPicker.




回答2:


This does work but only for Windows Phone 8.1 (Windows Phone) and not Windows Phone 8.0/8.1 (Windows Phone Silverlight).

Here is the code:

FileOpenPicker singleFilePicker = new FileOpenPicker();
        singleFilePicker.ViewMode = PickerViewMode.Thumbnail;
        singleFilePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        singleFilePicker.FileTypeFilter.Add(".jpg");
        singleFilePicker.FileTypeFilter.Add(".jpeg");
        singleFilePicker.FileTypeFilter.Add(".png");
        singleFilePicker.PickSingleFileAndContinue();

Add this method to handle the chosen photo(s):

public void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
    {
        if (args.Files.Count > 0)
        {
            var userChosenbPhoto = args.Files[0].Name;
        }
        else
        {
            //user canceled picker
        }
    }

You can also grab multiple files, too.

Last but most importantly, you need to add a continuation manager class to your project. This will manage the reactivation of the app when returning from a picker. Go to this documentation to learn how to add a ContinuationManager to the project (sorry for a link, too much info to put here).




回答3:


You can only use the FileOpenPickerfrom native apps, like the Direct3D ones.

You can use the PhotoChooserTask instead to select a picture from the Pictures Hub.




回答4:


According to the documentation, it is mentioned that: Minimum supported phone : None supported

Check this link for details http://msdn.microsoft.com/en-us/library/windowsphone/develop/br207852.aspx



来源:https://stackoverflow.com/questions/15357363/openfilepicker-not-working-on-windows-phone-8-specified-method-is-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!