How to write in ContactStore.Contact.Phones?

In my application, I create contacts using StoredContact and ContactStore by setting a mobile number using KnwonContactProperties.MobileTelephone via GetPropertiesAsync .

This is good, and I see the mobile number in People.

But...

If I try to access contacts programmatically through ContactManager.RequestStoreAsync , I do not see this phone number in the contacts collection ..

Is there any way to get the numbers recorded in the collection of phones?

( Related question )

+7
c # uwp windows-10-mobile
source share
1 answer

The KnownContactProperties class is under the Windows.Phone.PhoneContract namespace, but ContactManager.RequestStoreAsync () is under the Windows.ApplicationModel.Contacts namespace. This may be the reason you cannot get phone numbers. The ContactStore.CreateOrOpenAsync method on Windows.Phone.PhoneContract the same as the KnownContactProperties can work well. Below is a completed demo to enter a contact, and then enter a name and phone number.

XAML Code

 <StackPanel> <TextBox x:Name="txtName" Header="name" InputScope="NameOrPhoneNumber"/> <TextBox x:Name="txtTel" Header="phone number 1" InputScope="ChineseHalfWidth"/> <TextBox x:Name="txtTel1" Header="phone number 2" InputScope="TelephoneNumber"/> <Button x:Name="btnSave" Content="Save" Click="btnSave_Click"/> <Button x:Name="btnGet" Content="GET" Click="btnGet_Click"/> </StackPanel> 

Code for

  private async void btnSave_Click(object sender, RoutedEventArgs e) { var name = txtName.Text; var tel = txtTel.Text; ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); ContactInformation contactInformation = new ContactInformation(); contactInformation.DisplayName = name; var contactProps = await contactInformation.GetPropertiesAsync(); contactProps.Add(KnownContactProperties.MobileTelephone, tel); StoredContact storedContact = new StoredContact(contactStore, contactInformation); await storedContact.SaveAsync(); } private async void btnGet_Click(object sender, RoutedEventArgs e) { ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); var result = contactStore.CreateContactQuery(); var count = await result.GetContactCountAsync(); var list = await result.GetContactsAsync(); foreach (var item in list) { var properties = await item.GetPropertiesAsync(); System.Diagnostics.Debug.WriteLine(item.DisplayName); System.Diagnostics.Debug.WriteLine(properties[KnownContactProperties.MobileTelephone].ToString()); } } 
+1
source share

All Articles