1. Start the system Select Contact interface
Intent Intent = new Intent (Intent. Action_pick,contactscontract. Contacts. Content_uri);
Startactivityforresult (Intent, 0);
2. Overriding the Onactivityresult method to get the data
@Override
Public void Onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
if (data!=null) {
switch (requestcode)
{
Case 0:
Uri conatctdata = Data.getdata ();
cursor cursor = managedquery (conatctdata, NULL, NULL, NULL , or null);
if (Cursor.movetofirst ()) {
String contactId = cursor.getstring (Cursor.getcolumnindex (contactscontract.contacts._id));
String names = cursor.getstring (Cursor.getcolumnindexorthrow (ContactsContract.Contacts.DISPLAY_NAME)) ;
Cursor phones = getcontentresolver (). query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, NULL, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" +contactid, null, NULL);
String phonenum= "";
if (Phones.movetofirst ()) {
phonenum = phones.getstring (Phones.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER));
}
Name.settext (names);
Phone.settext (phonenum);
if (Build.VERSION.SDK_INT <14) {
phones.close ();
}
}
if (Build.VERSION.SDK_INT <14) {//Do not add Android4.0 above system operation will error
cursor.close ();
}
Break ;
}
}
}
3. Add Permissions
<uses-permission android:name="Android.permission.READ_CONTACTS"/>
Android Select contacts Echo