Content provides is essentially an interface, backdoor, he provides data to others, system contacts is a more complex content of the person.
Find /data/data/com.android.providers.contacts/contacts2.db
This directory also has a file contacts2.db.-journal, which is related to the transaction of the database
Main structure of the contact application database
Raw_contacts Contacts Table contact_id contact ID
Data data table raw_contact_id contact ID,mimetype_id class ID ,data1 data
Mimetypes Type table 1 Email,5 phone,7 name
To find all contact information:
- Query the raw_contacts table to take the contact ID out
- Query The data table based on the ID , and take out all the information
- The type of business that gets data based on the mimetype_id Query of the data mimetypes table
Query the system source code, find providers/contacts Related, first find the manifest file, see the <Provider> node,name Properties, and authories attribute, the hostname part is separated by semicolons contacts;com.android.contacts The lower version is the previous one, and the higher version is the latter one.
Find the source code to define the rules where the urimatcher object, see the actual rules, usually the table name, so the actual Uri path is content:// com.android.contacts/ Table name
Gets the contentresolver object that invokes the object's query (URI) method, parameter:URI is the path
Get cursor object, loop cursor object
Read content://com.android.contacts/raw_contacts No problem
An error occurred while reading Content://com.android.contacts/data, themimetype_id field does not exist , Actually walk the view chart, when you are unsure of the field, call the Cursor object's getcolumnnames () method, return the field array, print
The fields here should be data1 and mimetype .
Call the Cursor object's query () method, note the condition,"raw_contact_id=?" and the value new String[]{id}
Many of the world's applications are to take out the contact information, social applications generally have to send messages to each other, read system contacts
You need to define permissions:<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
Activity
Contentresolver resolver=Getcontentresolver (); Uri URI=uri.parse ("Content://com.android.contacts/raw_contacts"); Uri Datauri=uri.parse ("Content://com.android.contacts/data"); //Circular Contact TableCursor Cursor=resolver.query (URI,NULL,NULL,NULL,NULL); while(Cursor.movetonext ()) {String ID=cursor.getstring (Cursor.getcolumnindex ("contact_id")); //Find data TablesCursor Datacursor=resolver.query (Datauri,NULL, "Raw_contact_id=?",NewString[]{id},NULL); while(Datacursor.movetonext ()) {String data1=datacursor.getstring (Datacursor.getcolumnindex ("Data1")); String mimetype=datacursor.getstring (Datacursor.getcolumnindex ("MimeType")); System.out.println ("Data1:" +data1+ ", MimeType:" +mimetype); } System.out.println ("=========="); }
[Android] Get contact information for your system