Reputation: 656
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
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
Upvotes: 0
Views: 3273
Reputation: 6178
At first you should at Contact Capability
for wp8 add from WMAppManifest.xml
for wp8.1 add from Package.appxmanifest
Now define a class PhoneContact
to store the data
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. N.B use the following namespace also
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);
}
}
Upvotes: 0
Reputation: 522
You cant' - stupid crappy MS don't even support contact import from vcard file. ALL MS want that you put every your data to their servers so they own it.
Upvotes: 0
Reputation: 1118
From the link you provided (emphasis added):
With Windows Phone 8, Microsoft introduces a new concept of "custom contact stores" [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. 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.
Upvotes: 3
Reputation: 2385
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
Upvotes: 1