android - 在android中存储联系人ID的 "correct"方法是什么

标签 android

我在市场上有一个应用程序,它通过使用联系人选择器来存储联系人的详细信息。当我从联系人选择器返回时,我一直在使用以下方法获取联系人:

cursor.getColumnIndex(ContactsContract.Contacts._ID)

我发现使用它是可以的,直到有人刷新了一个新的 ROM 或得到了一部新手机,然后所有的 ID 都改变了。

我查看了 android 文档并且看到了对使用 ContactsContract.Contacts.LOOKUP_KEY 的引用,但描述让我感到困惑“一个不透明的值,其中包含有关如何在其行 ID 更改为同步或聚合的结果。”

那么我应该使用什么来存储联系人 ID?

最佳答案

Lookup Key 是联系人的正确引用。

Contacts Provider / Contacts:

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/

相关文章:

java - 打开 Sqlite DB Android 时出现 FileNotFound 异常

android - 如何避免每次运行 Espresso 时出现 'Gradle build'

Android列表-列表标题中的编辑文本

android - 解析设备 token 为空

android - 如何将值传递给 Android 应用程序中的 Soap 服务(ASMX 服务)中的标志枚举参数

android - 弹出键盘时如何避免重新加载整页?

java - 将 onClick 函数添加到 ActionBar 中的项目 (Android)

android - ICS 键盘背面,主页按钮在覆盖上打开时不接触

java - 无法从 onClick Android 调用另一个方法 - 抛出非法状态异常

android - 在 LinearLayout 中对齐 TextView 和 ImageView