根据移动运营商对联系人进行分类

时间:2015-04-19 17:35:55

标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-8.1

我正在使用Windows手机应用程序搜索联系人,然后根据他们的移动运营商对其进行分类,因此它基本上搜索电话号码的前3位数字,以告知它属于哪个运营商,然后将它添加到列表,任何指导如何做到这一点,因为我完全是noob并通过反复试验,谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用Microsoft.Phone.UserData.Contacts类读取现有的联系人数据。以下是示例代码:

private void ButtonContacts_Click(object sender, RoutedEventArgs e)
{
    Contacts cons = new Contacts();

    //Add an event handler for SearchCompleted event
    cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

    //Read existing contacts, FilterKind.None will return all contacts
    cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs args)
{
    //Do something with the results
    //Following code simply prints the phone numbers
    foreach (Contact contact in args.Results)
       foreach (ContactPhoneNumber phoneno in contact.PhoneNumbers)
          Debug.WriteLine(phoneno.PhoneNumber);    
}

您需要在WMAppManifest.xml中为ID_CAP_CONTACTS添加功能声明。