【问题标题】:Get the list of Contacts on Windows 10 Phone获取 Windows 10 Phone 上的联系人列表
【发布时间】:2016-08-31 08:25:51
【问题描述】:

我需要知道如何在 Windows 10 Phone 上阅读联系人列表。我不想使用联系人选择器;我只需要能够遍历所有联系人以访问他们的姓名和电话号码,并将其存储在列表中。 (类似于 WhatsApp 如何读取您的联系人列表并将其显示在他们的应用中)

【问题讨论】:

  • 是的,我们都想这样做。你都尝试了些什么?你知道 API 是否存在吗?

标签: xamarin windows-phone uwp contacts windows-10-mobile


【解决方案1】:

我从另一个答案here 中获取了一些代码。

使用此代码,您应该能够获取联系人。

public async Task IterateThroughContactsForContactListId()
 {            
            ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);

            var contacts = await allAccessStore.FindContactsAsync();
            foreach (var contact in contacts)
            {
                //process aggregated contacts
                if (contact.IsAggregate)
                {
                    //here contact.ContactListId is "" (null....)                  
                    //in this case if you need the the ContactListId then you need to iterate through the raw contacts
                    var rawContacts = await allAccessStore.AggregateContactManager.FindRawContactsAsync(contact);
                    foreach (var rawContact in rawContacts)
                    {
                        //Here you should have ContactListId
                        Debug.WriteLine($"aggregated, name: {rawContact.DisplayName }, ContactListId: {rawContact.ContactListId}");
                    }
                }
                else //not aggregated contacts should work
                {
                    Debug.WriteLine($"not aggregated, name: {contact.DisplayName }, ContactListId: {contact.ContactListId}");
                }
            }

}

他还指出:

非常重要:在 appxmanifest 中,您必须添加联系人 能力。在解决方案资源管理器中右键单击它并“查看代码” 然后在 Capabilities 下放

<uap:Capability Name="contacts" />

没有用于此的用户界面。见this

【讨论】:

  • 谢谢,这正是我所需要的,它工作得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多