Colca
Colca

Reputation: 41

Adding contacts to People on Windows Phone 8.1 in C#

Is there a way to add contacts from my app to the People app on a Windows Phone 8.1? I looked at different things under the Contact class and nothing seems to work. There are different ways (like ContactManager, ContactPicket, etc.) to retrieve data but nothing seems to allow me to add a new contact as most of the stuff like SaveContactTask in Microsoft.Phone.Tasks is not implemented on WP 8.1.

J.

Upvotes: 1

Views: 1745

Answers (1)

Anya Shenanigans
Anya Shenanigans

Reputation: 94859

You don't have write access to the primary contact store on Windows Phone 8, but you have the ability to create your own contact store for the app which you can use to manage contacts created in your own app.

The mechanism is pretty simple:

using Windows.Phone.PersonalInformation;

public async void addPerson() {
    var store = await ContactStore.CreateOrOpenAsync();

    var contact = new StoredContact(store) {
        DisplayName = "Mike Peterson"
    };
    var props = await contact.GetPropertiesAsync();
    props.add(KnownContactProperties.Email, "[email protected]");
    props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");

    await contact.SaveAsync();
}

To inform the OS that you provide contact information, you need to add the ID_CAP_CONTACTS/Contacts capability to your app (in the Capabilities section of the appxmanifest). Contacts remain until the app is removed.

Private, owned by the app contacts are convenient for 'contact' data for the app.

Upvotes: 4

Related Questions