_联系人数据库中的 ID 列
我读到不同表中的不同条目通过该表中的 _ID 列链接。例如,一个联系人可能有一个 _ID = 1 我通过
ContactsContract.Contacts._ID
,现在我想使用读取该联系人的电话号码
Cursor phoneCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId , null, null);
//...
String number = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
String id = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone._ID));
这工作正常,但我期望的是,如果联系人的 _ID 为 1,则该联系人的 _ID电话号码也是一,因为它们属于同一组,但它们不相等。那么问题是Android如何匹配这些条目呢?
谢谢,A.
I read that the different entries in different tables are linked via the _ID column in that table. For example a contact might have an _ID = 1 I get via
ContactsContract.Contacts._ID
and now I want to read the phone number of that contact using
Cursor phoneCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId , null, null);
//...
String number = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
String id = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone._ID));
This works fine, but what I would expect is that if the _ID of the contact is 1 that the _ID of the phone number is as well one since they belong together, but they are not equal. So the question is how does Android match these entries?
Thanks, A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个联系人对应 1 个或多个原始联系人。联系人的实际数据存储为
每个数据项包含其所属的原始联系人的 ID。
每个原始联系人都包含其所属联系人的 ID。
因此,给定一个联系人 ID,您就可以找到它代表的原始联系人。获取原始联系人 ID,然后查找该联系人中包含哪些数据。
A contact corresponds to 1 or more raw contacts. The actual data for the contact is stored as
Each data item contains the id of the raw contact it belongs to.
Each raw contact contains the id of the contact it belongs to.
So, given a Contact id you can find what raw contacts it represents. Get the raw contact ids and then find what data is within this contact.
当您看到数据库表时,您可以获得更多详细信息
据我所知,
这是我使用 sqlite3 数据库浏览器查看 android contact2.db 文件获得的信息我创建了一些 6 个联系人来测试联系人表中的 android 联系人
_id 和raw_contact_id 实际上是相同的(这意味着 ContactsContract.Contacts 提供者)
我们使用 mimetype Id 作为 where 条件来获取人员的真实详细信息,例如电话号码和电子邮件以及名字和姓氏
在数据表中,当考虑数据表使用 raw_contact_id 作为 where 时, 获取联系人特定记录的条件
ex 我的 raw_contact_id 是 1
我有 3 行,其中包含 data1 列中的电子邮件、电话和显示名称,
您可能会问,如果我们只想要电话、电子邮件或显示名称怎么办... 条件
您将需要 mimetype_id 作为获取电话号码的 mimetype_id 为 5
获取 display_name mimetype_id 为 6
要获取电子邮件 mimetype_id 为 1,
如果您是初学者,您可能无法理解所有这些内容...但是一旦您看到内部表,您就会得到我告诉您
只能通过 contact_id 或 raw_contact_id 而不是通过 _id 访问联系方式详细信息的 所有内容每个表中都有..该列用于不同的目的..
您可以看看我在这张图片中所说的内容
http://img94.imageshack.us/i/tablesxa.jpg
you could get more details when you see the database tables
as far as my understanding goes this is the information I got from viewing android contacts2.db file using sqlite3 db browser
I created some 6 contacts for testing my android contacts
in contacts table the _id and raw_contact_id is actually same (it means that ContactsContract.Contacts provider )
in data table we get the real details of the person like phone number and email and firstname and last name using mimetype Id as the where condition
when considering data table use raw_contact_id as the where condition to get a particular records of the contact
ex my raw_contact_id is 1
I got 3 rows which consists of email, phone and display name in data1 column
you may ask that what if we want only phone or email or display name ....there you will need the mimetype_id as the where condition
to get phonenumber mimetype_id is 5
to get display_name mimetype_id is 6
to get email mimetype_id is 1
you may not understand all these stuff if you are a beginner ...but once if u see the internal tables u get every thing which I told you
access contact details only by contact_id or raw_contact_id and not by _id which is in every table ..that column is for different purpose ..
you can have a look at what Im saying in this image
http://img94.imageshack.us/i/tablesxa.jpg