Get contacts on Windows Phone

Source: Internet
Author: User

Windows Phone SDK 7.1 provides an API for obtaining contact list information. Although it is read-only, it is quite good than SDK 7.0. The related APIs for obtaining Contact information are located in the Microsoft. Phone. UserData space. Two main types are used for obtaining Contact information: Contacts and Contact. The following are examples of getting contact information and precautions.
1. First, create a Contacts object and query the contact information asynchronously. Therefore, you need to add a query completion event (SearchCompleted)
Contacts contacts = new Contacts ();
Contacts. SearchCompleted + = new EventHandler <ContactsSearchEventArgs> (SearchCompleted );
2. Call query to start searching for contacts.
Contacts. SearchAsync (String. Empty, FilterKind. DisplayName, null );
SearchAsync (stringfilter, FilterKind filterKind, Object state) asynchronously searches for contact information in the user's contact data. filter is the filter, FilterKind filter type, and all contact information is queried in the above column.
3. After the query is complete, the query completion event (SearchCompleted) will be called)
Private void SearchCompleted (object sender, ContactsSearchEventArgs e)
{
Foreach (Contact result in e. Results)
{
// Contact name
String name = Contact. DisplayName;
// Contact phone number
ContactPhoneNumber phoneNumber = Contact. PhoneNumbers. FirstOrDefault ();
String phone = String. Empty;
If (phoneNumber! = Null)
{
Phone = phoneNumber. PhoneNumber;
}
// Contact address
ContactAddress address = Contact. Addresses. FirstOrDefault ();
String addr = String. Empty;
If (address! = Null)
{
Addr = address. PhysicalAddress. AddressLine1;
}
// Contact Email
ContactEmailAddress emailAddress = Contact. EmailAddresses. FirstOrDefault ();
String email = String. Empty;
If (emailAddress! = Null)
{
Email = emailAddress. EmailAddress;
}
//............
}
}
Note 1: If FirstOrDefault () is a function of the System. Linq. Enumerable class, you must manually add the namespace using System. Linq;
NOTE 2: To obtain the contact address PhysicalAddress. AddressLine1, you must add the reference System. Device.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.