[Android] get the contact information of the system
Content provision is essentially an interface and a back door. It provides data to others. The system contact is a more complex content passer.
Find / data / data / com.android.providers.contacts/contacts2.db
There is also a file contacts2. DB. - Journal in this directory, which is related to database transactions
Main structure of contact application database
raw_ Contacts contact table_ ID contact ID
Data table raw_ contact_ Contact ID, mimeType_ ID data class ID, data1 data
Mimetypes type table 1 email, 5 phone, 7 name
Query all contact information:
Query the system source code and find the related providers / contacts. First find the list file and see the < provider > node, name attribute and authors attribute. The host name part is semicolon separated contacts; Com.android.contacts the lower version is the former, and the higher version is the latter.
Find the place where the source code defines the rule and the place where the urimatcher object is located. Look at the actual rule. It is generally the table name, so the actual URI path is content://com.android.contacts/ Table name
Get the contentresolver object and call the query (URI) method of the object. The parameter: URI is the path
Get the cursor object and cycle the cursor object
read content://com.android.contacts/raw_ Contacts no problem
read content://com.android.contacts/data Error while, mimeType_ The ID field does not exist. When you are not sure about the field, call the getcolumnnames () method of the cursor object to return the field array and print it
The fields here should be data1 and mimeType
Call the query () method of the cursor object and write the condition, "raw"_ contact_ id=?” And value new string [] {ID}
Many applications in the world take out contact information. Social applications generally send information to each other and read system contacts
Permissions need to be defined: < uses permission Android: name = "Android. Permission. Read_contacts" / >
Note: if an account is deleted, it is not really deleted, but raw_ Contacts in the contacts table_ If the ID is null, you should add a to judge whether it is empty= null
activity: