It’s getting rather cold in UK and I am dreading the winter and the darkness. However, on the positive side it is cozier to sit and code in front of the computer with a lovely cup of tea or coffee. And here is some code.
I was asked on Twitter to post about adding contacts for Windows Store and Windows Phone when working on a Universal App, and frankly contacts and the various APIs around that confuses me (so I hope I got it right). This is one of the areas where we don’t have full convergence yet between the two targeted devices, some types are available for one platform (such as the ContactManager class which at the time of typing is only available for Windows Store). To add to the confusion there is the concept of a contact store, an in-app contacts keeper we could call it, which is available on Windows Phone only. After reading the documentation up and down I ended up with the code below for adding contacts to the People app (or hub as it can also be called) for Windows Phone and Windows Store. Whatever you want to do outside of the app container has to be done through either special permissions (- and capabilities declared) when they exist, or through a broker model that basically hands over the decision making over to the user.
In the code example below the Store application creates a contact, then opens up a dialog with the details and the user can either take direct actions on the details (send an email for example), or add the contact (unless already added)- from where the user can find the contact details in the People hub/app.
For Windows Phone the contact is added directly and can afterwards be accessed in the People hub. The app, if you are curious, is the app I’ve used for the last few Optical Character recognition blog posts and it simply takes an image, grabs the text and layout information and with some regex and layout information trickery (logic) creates a contact. Don’t forget to add Contact as a capability for Windows Phone in the manifest file BTW!
if (Contact == null) return;
var contact = new Contact
FirstName = Contact.Name
var homeEmail = new ContactEmail
Address = Contact.Email,
Kind = ContactEmailKind.Work
var workPhone = new ContactPhone
Number = Contact.PhoneNumber,
Kind = ContactPhoneKind.Work
ContactManager.ShowContactCard(contact, new Rect(), Placement.Above);
var contactStore = await Windows.Phone.PersonalInformation.ContactStore.CreateOrOpenAsync(
var contact = new StoredContact(contactStore);
var contactDetails = await contact.GetPropertiesAsync();
For Windows Store there is also the CurrentPickerUI which (when used with a Contact contract) lets the user use your app to select contacts in a similar fashion as the Share Contract target and source works.
Alright, let me know if I’ve missed something here or something, I can’t wait until Windows Store and Windows Phone become one and the APIs are a bit clearer in the way they work and what they do. Still love it though, the platform.