ContactPicker does not work on Windows Phone 8.1 Silverlight

I tried to get contact information in the Windows Phone 8.1 SL application, following Quickstart: selecting user contacts

In my function

private async void PickAContactButton_Click(object sender, RoutedEventArgs e) { var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker(); contactPicker.desiredFieldsWithContactFieldType.add(Windows.ApplicationModel.Contacts.ContactFieldType.email); Contact contact = await contactPicker.PickContactAsync(); // this throws System.NotImplementedException // Additional information: The method or operation is not implemented. if (contact != null) { ... } } 

The exact same function works in Windows Phone 8.1 RT. The ContactPicker class ContactPicker supported in both WP 8.1 RT and WP 8.1 SL according to this link .

Any idea what is going on?

+5
source share
1 answer

I had this behavior today in the Universal Store app for Win 8.1, so this can help you. I had various exceptions (FileNotFoundException and just System.Exception), so I'm not sure if this is the same problem.

As for my experiments, this is what ContactPicker currently needs to work:

  • ContactPicker instance must be created in the UI thread
  • contactPicker.DesiredFieldsWithContactFieldType must have exactly one element (exception from 0 or> 1 elements)

Here is what I did:

 // using Windows.ApplicationModel.Core; // in an async method: Contact user = null; AutoResetEvent resetEvent = new AutoResetEvent(false); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, (async ()=>{ ContactPicker contactPicker = new ContactPicker(); contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber); user = await contactPicker.PickContactAsync(); resetEvent.Set(); } ); resetEvent.WaitOne(); if (user != null) { // do smth } 
+1
source

Source: https://habr.com/ru/post/1204926/


All Articles