How can I query Windows 8's People app?

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?

Upvotes: 1

Views: 859

Answers (3)

Archita
Archita

Reputation: 11

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();
        }

Upvotes: 1

Mayank
Mayank

Reputation: 8852

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();

Upvotes: 1

John Koerner
John Koerner

Reputation: 38077

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();
}

Upvotes: 2

Related Questions