Wednesday, September 8, 2010

Android Contacts DB Internal


Important Contact DB Tables:
This article describes few of the important tables of Contact Application Database- raw_contacts, contacts and data. Following section will describe usage of few of the important columns of these tables-


raw_contacts- stores entries for all contacts. So if you have 100 contacts, there will be 100 records in this table. For the purpose of data normalization and reduce data redundancy,  this table stores basic contacts details and foreign keys of other tables (e.g. contacts tables) which in turn stores particular contact details like count of links, whether contact has email id etc.
Column Name
Purpose
Id
unique ID for each Contact
display_name
Contact name (first and last name are clubbed together)
display_name_reverse
. This column is read when you set display order “reverse” instead of display_name
account_type
Source of the account- SIM, Phone, Google, T-Mobile etc. There can be one entry for the owner profile vnd.sec.contact.my_profile
contact_id
Foreign key for contacts table. This field is important when contacts are linked.

Contacts- this table is directly referred while creating Contact List. If a contact is linked with another, its entry will be deleted from this table and will not be displayed in the Contact List.
Column Name
Purpose
Id
unique ID for each Contact
display_name
Contact name (first and last name are clubbed together). Same as raw_contacts table
display_name_reverse
Same as raw_contacts_table
link_type1
Same as account_type of raw_contacts
link_count
How many contacts are linked to this contact
has_email
Probably it helps to quickly check whether a contact has email id rather than reading entry from data table.

Data- this table stores all possible contact details e.g. multiple phone numbers, emails, icons, birthday, company name etc.
Column Name
Purpose
mimetype
Type of data. 5- display name, 6-phone _number, 1- email, 7-contact icon etc.
raw_contact_id
Foreign key for contacts table. This field is important to find out primary entries of a particular contact
data1
Stores contact details row wise. So for 3 details e.g. , and , there will be 3 rows.
data2
. (Fix me: some other numerical code also present.)
data3
. (Fix me: some other numerical code also present.)
data15
Stores contacts icons in binary format (PNG)


Important Contact URI and Sample Usage

content://com.android.contacts/raw_contacts_with_photo

Authority: com.android.contacts (It identifies the ContactsProvider class. So in all URI it will be a constant part.)
Authority Information defined in ContactsProvider Manifest-
<provider android:name="ContactsProvider2"
android:authorities="contacts;com.android.contacts"
../>

Path: raw_contacts_with_photo

Following is a list of important URI to access 3 different tables of Contact Application i.e. contacts, raw_contacts and data- 
Accessing Contacts Table
content://com.android.contacts/contacts
content://com.android.contacts/contacts/#
content://com.android.contacts/contacts/#/data
Accessing Raw_Contacts Table
content://com.android.contacts/raw_contacts
content://com.android.contacts/raw_contacts/#
content://com.android.contacts/raw_contacts/#/data
Accessing Data Table
content://com.android.contacts/data
content://com.android.contacts/data/#
content://com.android.contacts/data/phones
content://com.android.contacts/data/phones/#
 

No comments:

Post a Comment