The contact information in the Android phone is saved in data\data\com.android.providers.contacts\databases\contacts2.db. Mainly has
Raw_contacts table: The ID used to store the contact person;
Data table: The specific information used to store the contact person;
Mimetypes table: Save data type.
1 Public classContactinfoprovider {2 3 Privatecontext context;4 5 PublicContactinfoprovider (Context context) {6 This. Context =context;7 }8 9 /**Ten * Return information for all contact persons One * A * @return - */ - PublicList<contactinfo>Getcontactinfos () { the - //deposit all contacts into the collection -list<contactinfo> infos =NewArraylist<contactinfo>(); - //gets the Uri that corresponds to the raw_contacts table +Uri uri = uri.parse ("Content://com.android.contacts/raw_contacts"); - //gets the Uri corresponding to the data table +Uri Datauri = Uri.parse ("Content://com.android.contacts/data"); A //parameter two: The column to be queried, that is, the ID of the contact person. Gets the result set returned by a query database atcursor cursor = context.getcontentresolver (). Query (URI,NewString[] {"contact_id"},NULL,NULL,NULL); - //Moving Cursors - while(Cursor.movetonext ()) { - //because we only need to query a column of data-the ID of the contact, so we pass in 0 -String id = cursor.getstring (0); - //specific information for encapsulating each contact inContactInfo info =NewContactInfo (); - //after we get the ID, we use the ID to query the data table for the contact details (data in data1). to //parameter two: null to return all columns back + //parameter three: Select condition returns a result set after querying in the data table -Cursor datacursor = Context.getcontentresolver (). Query (Datauri,NULL, "Raw_contact_id=?",NewString[] {ID},NULL); the while(Datacursor.movetonext ()) { * //datacursor.getstring (Datacursor.getcolumnindex ("MimeType")) Gets the data type of the specific data in the Data1 column, which is determined by the name of the contact person $ if("Vnd.android.cursor.item/name". Equals (Datacursor.getstring (Datacursor.getcolumnindex ("MimeType")))) {Panax Notoginseng //datacursor.getstring (Datacursor.getcolumnindex ("data1")) gets the specific data for the contact in the data1 column -Info.setname (Datacursor.getstring (Datacursor.getcolumnindex ("Data1"))); the}Else if("Vnd.android.cursor.item/phone_v2". Equals (Datacursor.getstring (Datacursor.getcolumnindex ("MimeType"))) {//whether the data type is a mobile phone number +Info.setphone (Datacursor.getstring (Datacursor.getcolumnindex ("Data1"))); A } the } + //Add a contact to the collection after each query. - Infos.add (info); $info =NULL; $ //Close Result set - datacursor.close (); - } the cursor.close (); - returninfos;Wuyi } the}
Android development tool Class 37_ Contactinfoprovider