The source code of Google, the contact person in the mobile phone, has been shared by contentprovider. The bottom layer of contentprovider is implemented by SQLite database, so all its operations on data are implemented by SQL, only URI is provided at the upper layer.
You can create contentprovider in two ways:
1. Create your own contentprovider
2. Add your data to an existing contentprovider, provided that you have the same data type and the write permission.
The contentresolver provided by android can be used to access the data provided by contentprovider.
The following shows how to use contentresolver to obtain the numbers of contacts and contacts on the mobile phone:
Public list <friend> loadcontacts () {list <friend> List = new arraylist <friend> (); // obtain the client contentresolver Cr = context. getcontentresolver (); cursor = CR. query (contactscontract. contacts. content_uri, null, null); If (cursor. movetofirst () {do {friend = new friend (); // contact name string contactsname = cursor. getstring (cursor. getcolumnindex (contactscontract. contacts. display_name); // The ID string PID of the contact in the database = cursor. getstring (cursor. getcolumnindex (contactscontract. contacts. _ id); // we recommend that you use lookup_key to replace cursor phonecursor = CR. query (contactscontract. commondatakinds. phone. content_uri, null, contactscontract. commondatakinds. phone. contact_id + "=" + PID, null, null); string number = NULL; If (phonecursor. movetofirst () {do {// Phone Number = phonecursor. getstring (phonecursor. getcolumnindex (contactscontract. commondatakinds. phone. number);} while (phonecursor. movetonext (); friend. name = contactsname; friend. phone = number; List. add (friend) ;}while (cursor. movetonext ();} return list ;}