1. Database of system contacts (3 most important tables)
(1) Raw_contacts Contact Form
Save the contact's ID contact_id
(2) Data sheet
Save the contact's data
(3) Mimetypes
MIME Data type Table
2. Thinking? How to get the data for a contact.
(1) query raw_contacts get all the contact ID;
(2) according to the ID query data table, to obtain the current contact information;
3. Because if you want to access ContentProvider, you must understand the URI settings (Authority,path, etc.); only the source code can be seen; Androidmanifest.xml is a manifest file that lists the authorities of Contactprovider and the permissions required to access the Address book;
4. Address Book Database structure introduction:
The table structure is as follows:
The contacts are stored in/data/data/com.android.providers.contacts/databases/contacts2.db, and the main tables are:
(1) Raw_contacts: The ID of the person who stored the contact,
The _id property is the primary key, declared as AutoIncrement, i.e. no manual setting is required, and other properties do not need to be manually set to have default values;
Display_name attribute is name;
(2) Mimetypes: The type of data stored, such as "Vnd.android.cursor.item/name" for "name" type of data, "VND.ANDROID.CURSOR.ITEM/PHONE_V2" for "phone" type of data ;
(3) Data: storage of specific information;
The Raw_contact_id property is used to connect the Raw_contacts table, each record represents a specific data, and our main data (email, phone, etc.) are stored in the database table;
DATA1 attribute holds total data;
DATA2 Properties:
-If the record holds a name, data2 the name of the store;
-If this record holds the phone, then data2 storage type, such as mobile phone, home appliance;
-If this record holds the organization, then the DATA2 storage type, such as company, other;
-If this record holds the address, then data2 storage type, such as residential, unit, etc.;
5. Programming Tips:
Uri
Add, delete, update operations to the Raw_contacts table:
URI = content://com.android.contacts/raw_contacts;
Add, delete, update operations to the data table:
URI = content://com.android.contacts/data;
Query the data table according to email:
URI = content://com.android.contacts/data/emails/filter/*
Query the data table based on the phone number
URI = content://com.android.contacts/data/phone/filter/*
if you want to query the phone by ID, you can
URI = content://com.android.contacts/data;
then the WHERE condition is: raw_contact_id=? and mimetype =?
MIMETYPE
Tel: vnd.android.cursor.item/phone_v2
Name: Vnd.android.cursor.item/name
Mail: Vnd.android.cursor.item/email_v2
Correspondence Address: Vnd.android.cursor.item/postal-address_v2
Organization: Vnd.android.cursor.item/organization
Photo: Vnd.android.cursor.item/photo
Constants in data
data._id: "_id"
Data.display_name: "Display_name"
DATA.DATA1: "Data1"
DATA.DATA2: "Data2"
data.raw_contact_id: "raw_contact_id"
Data.mimetype: "MIMETYPE"
Android (Java) Learning note 249:contentprovider Use to get system contact information