Zhao Yazhi _android System contact app analyzes and obtains data.

Source: Internet
Author: User

Mobile Contact Storage Location

Like a text message, under Data-data.


Cell Phone Contact Database parsingExport the Contacts2.db table and view it through Sqliteexpert
mimetypes table: Stored data type (phone, avatar, name, email)
FOREIGN Key:


raw_contacts table: The ID of the person who holds the contact
contact_id: Contact person iddisplay_name: Contact name
data table: Information to store contacts

DATA1: Contact data data2: indata1 in the Mimetypes table is worth the valuemimetype_id: Contact person id,data data belongs toFOREIGN Key:raw_contact_id: Associating with raw_contacts tablesmimetype_id: Associating with Mimetypes tables
Contact Form
FOREIGN Key

get information about a contact person:
    1. Query the Raw_contact table and get the ID of the contact person.
    2. Query the data table based on the ID of the contact, and get the corresponding information from the contact.
    3. Querying the Mimetypes table for data types
Insert a contact information
    1. Insert the Raw_contact table first to write a new contact ID
    2. Writes to the data table based on the newly created ID data1 mimetype
Mobile Contact Source code AnalysisIn the contact Code of the Android system, Androidmenifest.xml defines an interface that provides an external query

in Android contact, you define the Urimatcher for the contact.


The Contactscontractdata in the Android API provides us with a response method and a simple use case:Add Method

Query Method

Remove Update method


StepsGet content ParserQuerying DataShow Data
Main code
Package Com.example.android_readphone.provider;import Android.content.contentresolver;import Android.database.cursor;import Android.net.uri;import Android.provider.contactscontract;import android.test.androidtestcase;/** * Test Get contact *  * @author Zhaoyazhi *  */public class Phoneprovidertest extends androidtestcase {public void readcontacts () {Contentresolver contentresolver = GetContext (). Getcontentresolver (); Cursor C = contentresolver.query (ContactsContract.RawContacts.CONTENT_URI, new string[] {"_id", "Display_name"  }, NULL, NULL, NULL), while (C.movetonext ()) {String id = c.getstring (c.getcolumnindex (contactscontract.rawcontacts._id)) ; String name = c.getstring (C.getcolumnindex ("display_name")); SYSTEM.OUT.PRINTLN ("Ordinal ID:" + ID + "----------name:" + name);} C.close ();}}


Output Result:

Android Contact System Source: http://download.csdn.net/detail/zhaoyazhi2129/7491109

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.