//Contact Information Public voidBt5_onclick (View v) {//Get callerContentresolver contentresolver=Getcontentresolver (); //Prepare URI//ContactsContract.Contacts.CONTENT_URI; //Call providerCursor cursor=contentresolver.query (ContactsContract.Contacts.CONTENT_URI,NULL,NULL,NULL,NULL); //iterating through the data collection if(cursor!=NULL) { while(Cursor.movetonext ()) {LongId=Cursor.getlong (Cursor.getcolumnindex (contactscontract.contacts._id)); String SName=cursor.getstring (Cursor.getcolumnindex (ContactsContract.Contacts.DISPLAY_NAME)); LOG.E ("TAG", "id=" +id+ "name=" +sName); //read the phone information for this contact personCursor c= getcontentresolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,NULL, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ "=?",NewString[]{id + ""},NULL); if(c!=NULL) { while(C.movetonext ()) {//Read the phone LongPid=C.getlong (C.getcolumnindex (contactscontract.commondatakinds.phone._id)); String Number=c.getstring (C.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER)); LOG.E ("TAG", sname+ "phone number =" +number+ "id=" +Pid); } c.close (); }} toast.maketext (mainactivity. This, "number of contacts =" +Cursor.getcount (), Toast.length_short). Show (); }Else{toast.maketext (mainactivity). This, "No contact information found", Toast.length_short). Show (); } }
Wangzai: Content provider Read phone contacts