private static Contact ContactFromContactInfo(WasmContact contactInfo) { var contact = new Contact(); contact.DisplayNameOverride = contactInfo.Name?.FirstOrDefault(n => n?.Length > 0) ?? ""; foreach (var phoneNumber in contactInfo.Tel?.Where(t => t?.Length > 0) ?? Array.Empty <string>()) { var contactPhone = new ContactPhone() { Number = phoneNumber, Kind = ContactPhoneKind.Other }; contact.Phones.Add(contactPhone); } foreach (var email in contactInfo.Email?.Where(t => t?.Length > 0) ?? Array.Empty <string>()) { var contactEmail = new ContactEmail() { Address = email, Kind = ContactEmailKind.Other }; contact.Emails.Add(contactEmail); } foreach (var address in contactInfo.Address?.Where(a => a != null) ?? Array.Empty <WasmContactAddress>()) { var contactAddress = new ContactAddress() { StreetAddress = address.DependentLocality ?? "", Country = address.Country ?? "", Locality = address.City ?? "", Region = address.Region ?? "", PostalCode = address.PostalCode ?? "", Kind = ContactAddressKind.Other }; contact.Addresses.Add(contactAddress); } return(contact); }
private async void CreateContact_Click(object sender, RoutedEventArgs e) { Windows.ApplicationModel.Contacts.Contact contact = new Windows.ApplicationModel.Contacts.Contact(); contact.FirstName = "TestContactWhatsApp"; Windows.ApplicationModel.Contacts.ContactEmail email = new Windows.ApplicationModel.Contacts.ContactEmail(); email.Address = "*****@*****.**"; email.Kind = Windows.ApplicationModel.Contacts.ContactEmailKind.Other; contact.Emails.Add(email); Windows.ApplicationModel.Contacts.ContactPhone phone = new Windows.ApplicationModel.Contacts.ContactPhone(); phone.Number = "4255550101"; phone.Kind = Windows.ApplicationModel.Contacts.ContactPhoneKind.Mobile; contact.Phones.Add(phone); Windows.ApplicationModel.Contacts.ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("WhatsAppContactList"); } else { contactList = contactLists[0]; } await contactList.SaveContactAsync(contact); //Add Annotation ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite); ContactAnnotationList annotationList; IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync(); if (0 == annotationLists.Count) { annotationList = await annotationStore.CreateAnnotationListAsync(); } else { annotationList = annotationLists[0]; } ContactAnnotation annotation = new ContactAnnotation(); annotation.ContactId = contact.Id; annotation.RemoteId = phone.Number; //associate the ID of a contact to an ID that your app uses internally to identify that user. annotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.AudioCall | ContactAnnotationOperations.VideoCall | ContactAnnotationOperations.ContactProfile; await annotationList.TrySaveAnnotationAsync(annotation); }