返回 raw_contact_id 或 contact_id ? Android 中的联系人 API
在 Contacts API 中,在 RawContact
表中查询联系人与在 Contacts
表中查询联系人是有区别的(如下所示:Data.RAW_CONTACT_ID
代码>或Data.CONTACT_ID
):
在什么情况下我可以检索联系人 ID,在其他情况下我可以检索 raw_contact ID? 例如,如果我们想选择一个联系人,它会返回 raw_contact_id 还是我查询的 contact_id?
这是文档中的代码:
Query
Finding all Data of a given type for a given contact
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
Data.CONTACT_ID + "=?" + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
new String[] {String.valueOf(contactId)}, null);
Finding all Data of a given type for a given raw contact
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
Data.RAW_CONTACT_ID + "=?" + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
new String[] {String.valueOf(rawContactId)}, null);
谢谢
in the Contacts API, there is a difference between querying a contact in the RawContact
table, and in the Contacts
table (as shown below : Data.RAW_CONTACT_ID
or Data.CONTACT_ID
) :
in which case can i retrieve the contact id, and in which other case will i retrieve a raw_contact id?
for example, if we want to pick a contact, will it return the raw_contact_id or the contact_id of my query?
Here's the code from the doc :
Query
Finding all Data of a given type for a given contact
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
Data.CONTACT_ID + "=?" + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
new String[] {String.valueOf(contactId)}, null);
Finding all Data of a given type for a given raw contact
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
Data.RAW_CONTACT_ID + "=?" + " AND "
+ Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
new String[] {String.valueOf(rawContactId)}, null);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Data._ID或Data.RAW_CONTACT_ID,它们都引用同一个联系人。
ContactsContract.RawContactsColumns.CONTACT_ID 也与 Data._ID 相同
You can use Data._ID or Data.RAW_CONTACT_ID, both of them refer to the same contact.
ContactsContract.RawContactsColumns.CONTACT_ID also is same as Data._ID