Project Description: The project is based on the Android platform phone Address Book, the main module is divided into four parts: contact management module, call records Management module, SMS Management module, System Setup module.
The system structure diagram is as follows:
Project start Date: May 28, 2014
Note: All source code of this development project will be shared to everyone. The purpose of this project is to develop these points: first, the ability to exercise independent development projects, second, to increase the understanding of Android development, third, familiar with the Android address Book mechanism.
Gossip not much said, officially started!
Technical point one: familiar with Android contact database contacts2.db
1. Get Contact Database contacts2.db file
Step one, open Eclipse and run the emulator;
Step two, bring up the file Explorer (from the toolbar, open Windows->show View, other--Android-> File explorer):
Step three, open the file browser, and under this directory data->data->com.android.providers.contacts->databases, Locate the database: contacts2.db, note: If you want to export the CONTACTS2.DB database on the real machine, the real machine must be root to export, or the Data directory layer will not open.
Step four, select Contacts2.db, and in the upper-right corner of the file Explorer, select the Export key to import the CONTACTS2.DB database to your computer.
Step five, download the database visualization software, to help us Open contacts2.db, see the table structure, here I recommend the use of Sqlitestudio, attached download link: Link address
Step six, install Sqlitestudio, after successful installation, open the software and import the CONTACTS2.DB database
Step seven, double-click the CONTACTS2 database, you can see all the tables in contacts2.db
Step nine, double-click the data table to see the structure of the table
Step ten, click on the data above the toolbar to view the contents of the table
2. Introduction of the CONTACTS2.DB database
Information about the address Book is placed in the CONTACTS2.DB database, the main use of this project development table is as follows:
Contacts table
The Contacts table is an aggregation of the raw Contact table by account type and account name, and the aggregation logic for the Contacts table is in the Contactaggregator.java file.
The structure diagram is as follows:
The data graph is as follows:
Raw_contacts table
The Raw_contacts table describes the data under each account of the contact, differentiated by account name and account Type field. That is, the same contact may have multiple records in the Raw_contact table, each of which belongs to a different account. So a contact_id may correspond to multiple raw_contact IDs, why a contact_id will correspond to multiple raw_contact_id, and I believe the reader will know the answer to this question. From here we also find that Android is allowing a contact to bind multiple accounts.
Fields to note are account_name,account_type,deleted, VERSION.
Account_name and Acount_type I do not describe in detail, the role of the deleted flag is that when deleting a user record, you can temporarily re-maintain a record of the deletion status, after the server side of the account is deleted, and then deleted from the local, In fact, the user can not care about the internal mechanism of the field, only need to be aware that when querying raw Contact table, you can filter out deleted records according to the deleted field. The Version field is also a useful field that can be used to determine if the contact information has changed, and if you have saved contact information locally, you can compare it to the system database's contact information based on the version information to determine if an update operation is required.
The structure diagram is as follows:
The data graph is as follows (two images merged together):
Data table
Data table stores the contact information, such as telephone, email and other information, from the figure below we can read each raw Contact table records will correspond to multiple data information, it is not difficult to understand that a person may have multiple phone numbers, multiple email, How is this information stored in the data table? It is not difficult to solve this problem by defining a specific description field that defines the type of the record, the MIME type, and then distinguishes the type of the record according to the MIME type, and then each information has its own type.
The structure diagram is as follows:
The data is as follows (two images merged together):
Calls table
The main function of the calls table is to store call logs, mainly using the date (date), number (phone numbers), type (call record type), name (contact name) of these fields.
The structure diagram is as follows:
The data graph is as follows (two images merged together):
Among the above tables, the relationships between the Contacts table, the Raw_contacts table, and the data table are as follows:
These three tables are the most important data table of the contact database, other data just provide some auxiliary functions, we first detail the structure of the three tables and how to use them.
From the books we can read contacts tables and Raw_contact tables are a one-to-many relationship, contacts tables are aggregations of raw_contact table records, that is, there is no account concept in the Contacts table, and Raw_ The contact form is an overview of a particular account of a person, and the data table stores the details of the contact, such as an email, a phone number, and so on.
Android Phone Address Book project development--Contact Database contacts2.db Introduction