Android Contacts Database Structure

Android contacts is a built-in application. It also provides content providers which the third-party app can use to manipulate android contacts, for example, add, delete, update and query contacts. This article will introduce detailed information about how the android contacts are implemented.

1. Android Contacts Overview.

  1. In an Android device, you can click the Phone —> Contacts icon to open the contacts list.
  2. When you click each contact you can see a lot of contact info listed such as mobile phone, work phone, display name, nickname, company, department, title, Website, etc.
  3. All the information for one contact is divided into 13 groups.
  4. Email ( address, email type(home, work, mobile, other)).
  5. Instant message ( protocol(qq, icq, skype etc), im id).
  6. Nickname.
  7. Organization ( company, department, title, job description,  office location).
  8. Phone ( number, phone type(home, mobile, work, other)).
  9. Address ( address, address type ( home, work, other)).
  10. Name (display name, given name, family name).
  11. Postal Address (country, city, region, street, postcode).
  12. Identity (namespace(SSN, passport), number).
  13. Photo.
  14. Group (contact belongs group id).
  15. Website (website url, website type()).
  16. Note.
  17. For some groups, such as email, phone, address, etc. The info is also classified according to data usage, such as use at home, at work, and others.

2. Where Are Contacts Stored In Android File System.

  1. All the android contact information is saved in the SQLite database. The database file is located at /data /data /com.android.providers.contacts /databases /contacts2.db.
  2. You can use the android device monitor to browse the above database file. If you can not open the above folder, run adb root shell command in a dos or shell window.

2.1 Operate Contacts Table Online Use SQLite3.

  1. You can run the below shell commands to operate the contacts table and data online.
    C:\Users\Jerry>adb shell 
    generic_x86:/ $ su 
    generic_x86:/ # sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db 
    SQLite version 3.9.2 2015-11-02 18:31:45 
    Enter ".help" for usage hints. 
    sqlite> select * from data; 
    sqlite> delete from data; 
    sqlite> delete from contacts; 
    sqlite> delete from raw_contacts;
  2. You can also click the top right button on the android device monitor to download the contacts database file to your local PC. And then use a client tool such as SQLiteSpy to browse the contacts database tables. Please read the article Android Device Monitor Cannot Open Data Folder Resolve Method to learn how to use an android device monitor.
  3. If you use SQLiteSpy to list all the tables in the android contacts database file contacts2.db. You can see that there are five key tables that are most important to know to store contacts information. The 5 tables are listed below.
  4. groups: Store contact group information.
  5. contacts: Store contacts information.
  6. raw_contacts: Has same _id value with contacts table, the difference is this table contains more contacts information columns than contacts table.
  7. mimetypes: Defines each contact information mime type.
  8. data: Store each contact field in one row, such as mobile phone, home phone, home email, work email, company, department, title, etc. Each row has a mimetype_id column, it’s value indicates what that row data means.

3. Key Android Contacts Tables.

3.1 The groups Table.

  1. Before adding any contact in android, you had better create a new group or select an existing contact group from this table.
  2. Double click the table name in SQLiteSpy’s left panel, it will list all the table columns in the right panel.
  3. The following two columns are most important.
  4. title: This is the group title you provided when you create it.
  5. notes: This column saves the group description info.

3.2 The contacts Table.

  1. This table stores contact id related information. It does not store contact summary information. The below columns is important in this table.
  2. _id: contact id.
  3. last_time_contacted: The last time this contact is contacted. The format is in milliseconds.
  4. contact_last_updated_timestamp: The timestamp this contact is updated for the last time.

3.3 The raw_contacts Table.

  1. This table is similar to the contacts table. But it contains more detailed summary contact information than the contacts table. Such as display_name, sort_key, etc.
  2. raw_contacts table columns.
  3. _id: The value is the same in the contacts table.
  4. display_name: The display name for this contact. Include first name, family name, etc.

3.4 The mimetypes Table.

  1. The mimetypes table is the most important table for android contacts. It has only 2 columns and has only 13 rows of data.
  2. The mimetypes table columns.
  3. _id: mimetype id.
  4. mimetype: Used to define android contact filed mime type. For example for contact information email field, it’s mimetype is vnd.android.cursor.item/email_v2.
  5. Below are the mimetype values. All those mimetype _id will be referenced in the data table, it indicates what contact info that row of data stores.
  6. vnd.android.cursor.item/email_v2 : Indicate this row store contact email info.
  7. vnd.android.cursor.item/im : The row store instant messaging info.
  8. vnd.android.cursor.item/nickname : The row store nickname info.
  9. vnd.android.cursor.item/organization : The row store contact organization info.
  10. vnd.android.cursor.item/phone_v2 : The row store contact phone info.
  11. vnd.android.cursor.item/sip_address :  The row store contact address info.
  12. vnd.android.cursor.item/name : The row store contact name info.
  13. vnd.android.cursor.item/postal-address_v2 : The row store postal address info.
  14. vnd.android.cursor.item/identity : The row store contact identity info.
  15. vnd.android.cursor.item/photo : The row store contact photo info.
  16. vnd.android.cursor.item/group_membership : The row store contact group info.
  17. vnd.android.cursor.item/website : The row store contact website info.
  18. vnd.android.cursor.item/note : The row store contact note info.

3.5 The data Table.

  1. The data table is the core table that stores android contact information. Each row store one contact information field.
  2. The contact filed data type is identified by the mimetype_id column value, and the contact user is identified by raw_contact_id column.
  3. Other columns from data1 to data15 are used to store contact info filed values.
3.5.1 The data Table Columns.
  1. mimetype_id: Reference _id column in mimetypes table. Used to indicate what data is stored in this row.
  2. raw_contact_id: Reference _id column in raw_contacts table. Used to indicate which contact this row belongs to.
  3. data1 to data15: For different mimetype, the data column stores different data type values. You can read the article Android Contacts Fields, Data Table Columns, And Data Mimetype Explain to learn more.

2 thoughts on “Android Contacts Database Structure”

  1. How did you get on with exporting contacts data, I would like to be able to download my entire contacts list into a database held on my own computer, not relying on Google. I am concerned that it needs to have the data separated in an easily understood way with similar headings to the smartphone. Not in a .csv style download.

    Any help or ideas will be much appreciated

  2. Hi Jerry,
    Hope you are fine,

    I need to get all my contacts from the “contacts2.db” file, I have made many trials but I wasn’t able to get all the contacts, I didn’t find all the recent important contacts and numbers.

    Is there a way we can cooperate in this issue please ?, as I really need them urgently.

    Waiting your kind feedback,
    Regards

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.