[Android] Get contact information for your system

Source: Internet
Author: User

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:

    1. Query the raw_contacts table to take the contact ID out
    2. Query The data table based on the ID , and take out all the information
    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.