Get phone Contacts

Source: Internet
Author: User

/**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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.