Set read permission
<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 );
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, 1000). 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, 1000). 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, 1000). show ();
}
Email. close ();
}
}