/**Get Library Phon table fields **/Private Static Finalstring[] Phones_projection =Newstring[]{phone.display_name, phone.number};/**Contact Display Name **/Private Static Final intPhones_display_name_index = 0;/**Phone number **/Private Static Final intPhones_number_index = 1;/**Get phone Contacts contact information **/ Public Static voidGetphonecontacts (activity activity, list<contactinfo>Contactinfos) {Contentresolver resolver=Activity.getcontentresolver (); //Get phone Contact personCursor phonecursor = Resolver.query (Phone.content_uri, Phones_projection,NULL,NULL,NULL); if(Phonecursor! =NULL) { while(Phonecursor.movetonext ()) {ContactInfo ContactInfo=NewContactInfo (); //get a cell phone numberString PhoneNumber =phonecursor.getstring (Phones_number_index); //when the cell phone number is empty or an empty field skips the current loop if(Textutils.isempty (phonenumber))Continue; //Get Contact NameString ContactName =phonecursor.getstring (Phones_display_name_index); Contactinfo.setcontactsname (ContactName); Contactinfo.setcontactsnumber (PhoneNumber); Contactinfos.add (ContactInfo); } //more than 4.0 of the version will be automatically closed (4.0--14;; 4.0.3--15) if(Integer.parseint (Build.VERSION.SDK) < 14) {phonecursor.close (); } }}/**Get mobile SIM card contact information for everyone **/ Public Static voidGetsimcontacts (activity activity, list<contactinfo>Contactinfos) {Contentresolver resolver=Activity.getcontentresolver (); //get Sims Card Contact personUri uri = uri.parse ("Content://icc/adn"); Cursor Phonecursor= Resolver.query (URI, Phones_projection,NULL,NULL, NULL); if(Phonecursor! =NULL) { while(Phonecursor.movetonext ()) {ContactInfo ContactInfo=NewContactInfo (); //get a cell phone numberString PhoneNumber =phonecursor.getstring (Phones_number_index); //when the cell phone number is empty or an empty field skips the current loop if(Textutils.isempty (phonenumber))Continue; //Get Contact NameString ContactName =phonecursor. getString (Phones_display_name_index); //no contact with the head image in the SIM card.Contactinfo.setcontactsname (contactName); Contactinfo.setcontactsnumber (PhoneNumber); Contactinfos.add (ContactInfo); } //more than 4.0 of the version will be automatically closed (4.0--14;; 4.0.3--15) if(Integer.parseint (Build.VERSION.SDK) < 14) {phonecursor.close (); } }}
Get phone Contacts