Android Contact Information Acquisition
Public class mainactivity extends activity {string ID, name, phonenumber, email; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); contentresolver = This. getcontentresolver (); cursor = contentresolver. query (Android. provider. contactscontract. contacts. content_uri, null, null); While (cursor. movetonext () {// to obtain the contact ID and nameid = cursor. getstring (cursor. getcolumnindex (Android. provider. contactscontract. contacts. _ id); name = cursor. getstring (cursor. getcolumnindex (Android. provider. contactscontract. contacts. display_name); // obtain the contact's phone number cursor phonecursor = contentresolver. query (Android. provider. contactscontract. commondatakinds. phone. content_uri, null, android. provider. contactscontract. commondatakinds. phone. contact_id + "=" + id, null, null); While (phonecursor. movetonext () {phonenumber = phonecursor. getstring (phonecursor. getcolumnindex (Android. provider. contactscontract. commondatakinds. phone. number); system. out. println ("ID =" + ID + "name =" + name + "phonenumber =" + phonenumber);} phonecursor. close (); // obtain the contact's phone number cursor emailcursor = contentresolver. query (Android. provider. contactscontract. commondatakinds. email. content_uri, null, android. provider. contactscontract. commondatakinds. email. contact_id + "=" + id, null, null); While (emailcursor. movetonext () {email = emailcursor. getstring (emailcursor. getcolumnindex (Android. provider. contactscontract. commondatakinds. email. data); system. out. println ("ID =" + ID + "name =" + name + "email =" + email);} emailcursor. close ();} cursor. close ();}}
Refer:
Android contact contacts