Set Read permissions
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
<uses-permission android:name= "Android.permission.WRITE_CONTACTS"/>
Main code
public void Readcontacts () {
cursor cursor = this.getcontentresolver (). Query (
ContactsContract.Contacts.CONTENT_URI, NULL, NULL, NULL, or NULL);
int contactidindex = 0;
int nameindex = 0;
if (Cursor.getcount () > 0) {
Contactidindex = cursor
. Getcolumnindex (contactscontract.contacts._id);
Nameindex = cursor
. Getcolumnindex (ContactsContract.Contacts.DISPLAY_NAME);
}
while (Cursor.movetonext ()) {
String contactId = cursor.getstring (Contactidindex);
String name = cursor.getstring (Nameindex);
Toast.maketext (this, name, +). Show ();
Cursor phones = this.getcontentresolver (). Query (
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, NULL,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?",
New string[] {contactId}, NULL);
if (Phones.movetonext ()) {
int Phoneindex=phones.getcolumnindex (ContactsContract.CommonDataKinds.Phone.NUMBER);
String phonenumber=phones.getstring (Phoneindex);
Toast.maketext (this, phonenumber, +). Show ();
}
Phones.close ();
Cursor email = this.getcontentresolver (). query (ContactsContract.CommonDataKinds.Email.CONTENT_URI, NULL, ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?",
New string[] {contactId}, NULL);
if (Email.movetonext ()) {
int Emailindex =email.getcolumnindex (ContactsContract.CommonDataKinds.Email.DATA);
String emailaddress=email.getstring (Emailindex);
Toast.maketext (this, emailaddress, +). Show ();
}
Email.close ();
}
}