gpt4 book ai didi

android - 如何唯一标识 ContactsContract.Contacts 表上的联系人

转载 作者:行者123 更新时间:2023-11-29 16:55:33 24 4
gpt4 key购买 nike

我有一个应用程序可以获取设备上联系人的 ContactsContract.Contacts.LOOKUP_KEY 并将其保存在应用程序数据库中。

看完this我认为我可以使用 LOOKUP_KEY 来唯一标识联系人,即使在编辑联系人时(例如在编辑联系人姓名之后)也是如此。

实际上我看到在编辑一个联系人后,它的 LOOKUP_KEY 发生了变化,所以我不能再使用我保存在我的应用数据库中的 LOOKUP_KEY

我的问题是:有没有一种方法可以唯一标识 ContactsContract.Contacts 上的联系人,从它在设备上首次创建到从设备中删除?

谢谢

最佳答案

LOOKUP_KEY 不能单独用作键,而是应该与联系人的 _ID 一起使用以形成完整的 lookupUri

然后可以使用 lookupUriCONTENT_LOOKUP_URI 表中查找联系人。CONTENT_LOOKUP_URI 基本上首先通过 _ID 查找联系人,如果找不到,或者 _ID 似乎是错误的联系人,它使用LOOKUP_KEY 部分的提示,尝试为您追踪正确的联系人。

来自 CONTENT_LOOKUP_URI

A content:// style URI for this table that should be used to create shortcuts or otherwise create long-term links to contacts. This URI should always be followed by a "/" and the contact's LOOKUP_KEY. It can optionally also have a "/" and last known contact ID appended after that. This "complete" format is an important optimization and is highly recommended.

As long as the contact's row ID remains the same, this URI is equivalent to CONTENT_URI. If the contact's row ID changes as a result of a sync or aggregation, this URI will look up the contact using indirect information (sync IDs or constituent raw contacts).

Lookup key should be appended unencoded - it is stored in the encoded form, ready for use in a URI.

来自 getLookupUri(long contactId, String lookupKey)

Build a CONTENT_LOOKUP_URI lookup Uri using the given _ID and LOOKUP_KEY.

来自 LOOKUP_KEY

An opaque value that contains hints on how to find the contact if its row id changed as a result of a sync or aggregation.

关于android - 如何唯一标识 ContactsContract.Contacts 表上的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45146732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com