Adding contacts to People on Windows Phone 8.1 in C#

懵懂的女人 提交于 2019-12-29 01:58:09

问题


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.


回答1:


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, "mike@peterson.com");
    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.



来源:https://stackoverflow.com/questions/27463192/adding-contacts-to-people-on-windows-phone-8-1-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!