The main thing is to use content parser to deal with the problem:
First, you should understand the Android phone contact database: Read the main use of 3 tables:
Table Name |
Role |
Contacts |
Record Contact ID, (there are a few columns that indicate several contacts). |
Mimetypes |
Storage type alignment (in order to save the database space) |
Data |
The contact information is saved in this table |
But in the process of checking, the first time we were looking at the table contacts, the second time we looked at View_data this view
The first loop has several contacts executed several times during the query, but the second cycle is performed up to 11 times per contact, depending on your contact store information
A piece of code drifts through:
Contentresolver Contentresolver =Getcontentresolver (); //querying with the cursor objectcursor cursor =contentresolver.query (Uri. Parse ("Content://com.android.contacts/raw_contacts"), NewString[] {"contact_id"},NULL,//query Condition "a=?" NULL,//provide a value for the question mark NULL); //Circular Cursors while(Cursor.movetonext ()) {//The cursor's index value starts at 0.String id = cursor.getstring (0); //query data tables and mimetype generated views based on uniqueness ID values, get data and MimeType fieldsCursor Indexcursor =contentresolver.query (Uri.parse ("Content://com.android.contacts/data"), NewString[] {"Data1", "MimeType" }, "Raw_contact_id=?",NewString[] {ID},NULL); //5 looping through cursor values the query process is still unclear.Hashmap<string, string> HM =NewHashmap<string, string>(); while(Indexcursor.movetonext ()) {//System.out.println (indexcursor.getstring (0) + "" + indexcursor.getstring (1));Hm.put (indexcursor.getstring (1), indexcursor.getstring (0)); } contactlist.add (HM); Indexcursor.close (); } //Close CursorsCursor.close (); //sending updated UI data in a child threadMessage msg =NewMessage (); Msg.what= 1; Mhandler.sendmessage (msg);
Read phone contacts in Android