我在市场上有一个应用程序,它通过使用联系人选择器来存储联系人的详细信息。当我从联系人选择器返回时,我一直在使用以下方法获取联系人:
cursor.getColumnIndex(ContactsContract.Contacts._ID)
我发现使用它是可以的,直到有人刷新了一个新的 ROM 或得到了一部新手机,然后所有的 ID 都改变了。
我查看了 android 文档并且看到了对使用 ContactsContract.Contacts.LOOKUP_KEY 的引用,但描述让我感到困惑“一个不透明的值,其中包含有关如何在其行 ID 更改为同步或聚合的结果。”
那么我应该使用什么来存储联系人 ID?
最佳答案
Lookup Key 是联系人的正确引用。
The ContactsContract.Contacts table also has the column LOOKUP_KEY that is a "permanent" link to the contact row. Because the Contacts Provider maintains contacts automatically, it may change a contact row's _ID value in response to an aggregation or sync. Even If this happens, the content URI CONTENT_LOOKUP_URI combined with contact's LOOKUP_KEY will still point to the contact row, so you can use LOOKUP_KEY to maintain links to "favorite" contacts, and so forth. This column has its own format that is unrelated to the format of the _ID column.
关于android - 在android中存储联系人ID的 "correct"方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9159229/