"The device is not ready (Exception from HRESULT: 0x80070015)" error when using a ContactPicker in a HelloWorld Windows Phone 8.1 applcation

0

I'm trying to create a small WP 8.1 application that displays a ContactPicker as it starts. I'm using Visual Studio Community 2015 on Windows 10 Preview build 10532 to create the application. So, as soon as I create a Windows Phone Blank App, I add a button and this code.

    public PivotPage()
    {
        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;

        this.navigationHelper = new NavigationHelper(this);
        this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
        this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

        this.pickContactCommandButton.Click += PickContactCommandButton_Click;
    }

    private async void PickContactCommandButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            ContactPicker contactPicker = new ContactPicker();
            IList<Contact> pickedContacts = await contactPicker.PickContactsAsync();
            int pickedCount = pickedContacts != null ? pickedContacts.Count : 0;
            if (pickedCount > 0)
            {
            }
        }
        catch (Exception ex)
        {
            MessageDialog md = new MessageDialog(ex.Message);
            await md.ShowAsync();
        }
    }

Then I deploy the app to my Windows Phone 8.1 phone with Denim version installed, and registered for development (https://msdn.microsoft.com/en-us/library/windows/apps/ff769508%28v=vs.105%29.aspx?f=255&MSPPError=-2147217396).

When I run the app on the phone and I press the button I get the message in the title and the contact picker doesn't show up. The problematic line is the one with await. It works well if I deploy the same app to my Windows 10 Mobile phone.

I have this set in the Package.appxmanifest file:

  <Capabilities>
    <m3:Capability Name="contacts" />
  </Capabilities>

What could be the problem?

c#
windows-phone-8
contactpicker
asked on Stack Overflow Sep 15, 2015 by robcsi

1 Answer

1

The reason why the contact picker didn't show and the exception was thrown is that this line of code was missing before calling the contact picker pick method:

    contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);

So, basically you need to add at least one ContactFieldType on Windows Phone 8.1, otherwise contact picker will crash...

Problem solved.

answered on Stack Overflow Sep 16, 2015 by robcsi • edited Sep 18, 2015 by robcsi

User contributions licensed under CC BY-SA 3.0