简体   繁体   English

阅读所有电话联系人并进行更新。 Windows Phone 8

[英]Read all phone contacts and update them. windows phone 8

I want to get all contacts stored in phone and update them as per requirement. 我想将所有联系人存储在手机中,并根据需要进行更新。

http://www.silverlightshow.net/items/Windows-Phone-8-Contacts-Integration.aspx http://www.silverlightshow.net/items/Windows-Phone-8-Contacts-Integration.aspx

This link shows to get contacts but I'm not getting all contacts. 该链接显示获得联系人,但我没有获得所有联系人。 I'm only getting contacts that have been created using my app. 我只会收到使用我的应用创建的联系人。

Is there any way I can get all contacts and change mobile numbers. 有什么办法可以获取所有联系人并更改手机号码。

Thanks 谢谢

From the link you provided (emphasis added): 通过您提供的链接(添加了重点):

With Windows Phone 8, Microsoft introduces a new concept of "custom contact stores" [2]. 通过Windows Phone 8,Microsoft引入了“自定义联系人存储” [2]的新概念。 In addition to the read-only access to the user's contact list and the above demonstrated way to use a separate task for creating new entries (both of which available in 7.x) we now are able to write our own data to the people hub silently and without user consent. 除了对用户的联系人列表具有只读访问权限以及上述使用单独的任务创建新条目(在7.x中均可用)的方式之外,我们现在还能够将自己的数据写入人员中心未经用户同意静默地进行。 However apps still cannot manipulate existing contacts that originate from somewhere else . 但是,应用程序仍然无法操纵来自其他地方的现有联系人 In this sense, the data that belongs to an app is somewhat isolated from the rest. 从这个意义上说,属于某个应用程序的数据与其余数据有些隔离。

This is by design, you can't edit contacts you didn't create. 这是设计使然,您不能编辑未创建的联系人。

try something like this 尝试这样的事情

void GetContact()
{
    cons = new Contacts();
    //Identify the method that runs after the asynchronous search completes.
    cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(ContactsSearchCompleted);
    //Start the asynchronous search.
    cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

private void ContactsSearchCompleted(object sender, ContactsSearchEventArgs e)
{
    cons.SearchCompleted -= ContactsSearchCompleted;
    //e.Results should be the list of contact, since there's no filter applyed in the search you shoul have all contact here
}

not this is a copy paste of an old not tested code of mine so you might have to change something 这不是我未测试的旧代码的复制粘贴,因此您可能必须更改某些内容

You cant' - stupid crappy MS don't even support contact import from vcard file. 您不能-笨拙的MS甚至不支持从vcard文件导入联系人。 ALL MS want that you put every your data to their servers so they own it. 所有MS都希望您将所有数据放入其服务器,以便他们拥有它。

At first you should at Contact Capability 首先,您应该在联络Capability

for wp8 add from WMAppManifest.xml WMAppManifest.xml添加wp8

在此处输入图片说明

for wp8.1 add from Package.appxmanifest 对于wp8.1,请Package.appxmanifest添加

在此处输入图片说明

Now define a class PhoneContact to store the data 现在定义一个PhoneContact类来存储数据

public class PhoneContact {
    public string Name { get; set; }
    public string Number { get; set; }
    public string Email { get; set; }
}

Create a ObservableCollection and Call the following action from constructor to read the contact list. 创建一个ObservableCollection并从构造函数中调用以下操作以读取联系人列表。 NB use the following namespace also NB也使用以下名称空间

using Microsoft.Phone.UserData;
using System.Collections.ObjectModel;

ObservableCollection<PhoneContact> phoneContact;
public MainPage() {
     InitializeComponent();
     phoneContact = new ObservableCollection<PhoneContact>();
     ReadPhoneContact();
}

void ReadPhoneContact(){
     Contacts cnt = new Contacts();
     cnt.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);
     cnt.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

After reading all contact fire the following event. 阅读所有联系人后,触发以下事件。 you can read multiple contact number, email etc. 您可以阅读多个联系电话,电子邮件等。

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
   foreach (var item in e.Results) {
      var contact = new PhoneContact();
      contact.Name = item.DisplayName;
      foreach (var pn in item.PhoneNumbers)
          contact.Number = string.IsNullOrEmpty(contact.Number) ? pn.PhoneNumber : (contact.Number + " , " + pn.PhoneNumber);
      foreach (var ea in item.EmailAddresses)
           contact.Email = string.IsNullOrEmpty(contact.Email) ? ea.EmailAddress : (contact.Email + " , " + ea.EmailAddress);
      phoneContact.Add(contact);
   }  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM