Android OneDayOneExample-2. Read phone book

Source: Internet
Author: User
Package COM. yarin. android. examples_03_02; import android. app. activity; import android. content. contentresolver; import android. database. cursor; import android. OS. bundle; import android. provider. contactscontract; import android. provider. contactscontract. phonelookup; import android. widget. edittext; import android. widget. textview; public class activity01 extends activity {public void oncreate (bundle savedinstancestate) {edittext edit = new edittext (this); string = ""; super. oncreate (savedinstancestate); // obtain the contentresolver object contentresolver Cr = getcontentresolver (); // obtain the cursor = CR for the first entry in the phone book. query (contactscontract. contacts. content_uri, null, null); // move the cursor down while (cursor. movetonext () {// get the contact name int namefieldcolumnindex = cursor. getcolumnindex (phonelookup. display_name); string contact = cursor. getstring (namefieldcolumnindex); // call String contactid = cursor. getstring (cursor. getcolumnindex (contactscontract. contacts. _ id); cursor phone = CR. query (contactscontract. commondatakinds. phone. content_uri, null, contactscontract. commondatakinds. phone. contact_id + "=" + contactid, null, null); While (phone. movetonext () {string phonenumber = phone. getstring (phone. getcolumnindex (contactscontract. commondatakinds. phone. number); string + = (contact + ":" + phonenumber + "\ n") ;}} cursor. close (); // set the content displayed in textview to edit. settext (string); // display to the screen setcontentview (edit );}}

Related Article

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.