Android contact analysis (1): Relationship between data, rawcontact, and contact

Source: Internet
Author: User

I. Preface:

Recently, the task has been completed temporarily. There is one or two days of idle time. Therefore, I want to sort out the android contact to facilitate myself later.

All database tables of Android contact have contacts2.db (Path:/data/COM. Android. providers. Contacts/databases/contacts2.db), It is called contact2 because it has been improved since Android 2.0 (API level5, to meet the needs of a contact who has multiple accounts (for example, a mobile phone address book and a Gmail Address Book), the contact database is based on Relational relationships. The relationships between them are as follows:

Ii. Table Data

The data table stores the contact details. Each row in the table stores a specific type of information, such as email, address, or phone, each row uses a mimetype_id field to indicate the type of data stored in the row. This field references the mimetyps table, which stores common data types.

Data fields of table data:

Descriptions of fields:

Mimetype_id
Indicates the type of information stored in the row

Raw_contact_id
Rawcontact to which the row belongs

Is_primary
This field indicates whether the data is the master data of raw contact, that is, its display name will be used as the display name of raw contact.

Is_super_primary
Whether the data is the master data of the contact to which it belongs. If is_super_primary is 1, is_primary must be 1.

Data1-data15
The data field is determined by mimetype_id. Generally, the data1 table is the primary information (such as phone number and email address), data2 indicates the secondary information, and data15 indicates the BLOB data (binary data). For example:
If the type is phone. content_item_type, data1 stores the phone number;
If the data type is email. content_item_type, data1 stores email addresses and so on.

Data_sync1 ~ Data_sync4
The fields used by sync_adapter. sync_adapter is used for data synchronization. For example, the Gmail account in your mobile phone is synchronized with the Google server.

Data_version
The data version used for data synchronization.

Iii. rawcontact

In the rawcontact table, each user stores the contact information. When a raw contact is inserted or the data of a raw contact changes, the system checks whether the raw contact matches other raw contacts (for example, if the raw contact data contains the same phone number or name ), if they match, they will be combined, that is, they will belong to the same cantact, as they reference the same cantact_id in the rawcontact table.

Rawcontact Data Field

4. Table contact

A contact table cannot be created. a row in the contact table represents a contact. It is a combination of one or more rows in the rawcontact table, the rows in the rawcontact table indicate different account information of the same person. The data in the contact is automatically generated by the system combination rawcontact table. You cannot directly insert data into this table. When a raw contact is inserted, the system first looks for the contact table to see if there is a record with the inserted raw contact to indicate the same person. If yes, insert the _ ID of the contact to the contact_id field of the raw contact record, the system automatically inserts a contact record and inserts its _ id into the contact_id column of the newly inserted raw contact.

Update operation:

Only the times_contacted, last_time_contacted, starred, custom_ringtone, and sene_to_voicemail columns in the contact table can be changed. changes to these columns will cause the corresponding raw contact to be changed.

Delete operation:

When a record in the contact table is deleted, the information of all accounts of a contact is deleted, that is, all raw contacts corresponding to the contact table are also deleted, the data corresponding to each raw contact is deleted, and the corresponding records on the server are also deleted during sync adapter synchronization.

Query operation:

Use content_lookup_uri instead of content_uri to search for the contact information (see below );
If you need to search for a contact by phone number, use phonelookup. content_fiilter_uri. This URI is optimized for this purpose;
If you need to search by matching some names, use content_filter_uri;
If you need to search for the table contactscontract. Data by email or address, the results include the contact ID and name.

V. Summary

This articleArticleI only talked about the relationship between the three tables and their respective fields. They are some principles. In addition to these three tables, they also involve the participation of other classes in actual operations, for example, contactscontract. data, contactscontract. commondatakinds, contactscontract. phonelookup and so on. In the next article, we will provide some examples to gain a deeper understanding of the principles.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.