How can I query Windows 8's People app?
-
13-07-2021 - |
Question
I need to extract the Name and email address from a user's People app so that I have a list of all of their contacts to display to them in a popup/flyout. How to do this?
Solution
You can't query them directly for security reasons. You can use the contact picker to allow the user to select single or multiple contacts.
You can instantiate the picker and then allow the user to select one or more contacts. For example:
ContactPicker cp = new ContactPicker();
var contacts = await cp.PickMultipleContactsAsync();
if (contacts != null && contacts.Count > 0)
{
MessageDialog md = new MessageDialog(contacts[0].Name);
md.ShowAsync();
}
OTHER TIPS
Here is the example of contact picker for multiple contacts, you can get the sample application from here
var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
contactPicker.CommitButtonText = "Select";
contacts = await contactPicker.PickMultipleContactsAsync();
var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker(); contactPicker.CommitButtonText = "Select";
contactPicker.SelectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.Fields;
contactPicker.DesiredFields.Add(Windows.ApplicationModel.Contacts.KnownContactField.Email);
ContactInformation contact = await contactPicker.PickSingleContactAsync();
if (contact != null)
{
contactName.Visibility = Visibility.Visible;
contactName.Text = contact.Name;
EmailValue.Visibility = Visibility.Visible;
EmailValue.Text = contact.Emails[0].Value.ToString();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow