Get All Details from Contacts in ANDROID.

Hi all..

In today’s post I will show you how to get all information from the ANDROID Contacts programatically.
Just copy and paste this code to your mail java file and check the Logcat for output.

package pack.coderzheaven;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;

public class GetContactsDemo extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    public void readContacts(){
    	 ContentResolver cr = getContentResolver();
    	 Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);

         if (cur.getCount() > 0) {
        	while (cur.moveToNext()) {
		        String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
		        String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
		        if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
		        	System.out.println("name : " + name + ", ID : " + id);

		        	// get the phone number
		        	Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
		         		    			   ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
		         		    			   new String[]{id}, null);
         	        while (pCur.moveToNext()) {
         	        	  String phone = pCur.getString(
         	        	  System.out.println("phone" + phone);

         	        // get email and type

         	       Cursor emailCur = cr.query(
         	    			ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
         	    			new String[]{id}, null);
     	    		while (emailCur.moveToNext()) {
     	    		    // This would allow you get several email addresses
     	    	            // if the email addresses were stored in an array
     	    		    String email = emailCur.getString(
     	    	 	    String emailType = emailCur.getString(

     	    		  System.out.println("Email " + email + " Email Type : " + emailType);

         	    	// Get note.......
         	    	String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
         	        String[] noteWhereParams = new String[]{id,
         	                Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null);
	         	 	if (noteCur.moveToFirst()) {
	         	 	    String note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
	         	 	  System.out.println("Note " + note);

	         	 	//Get Postal Address....

	         	 	String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
	         		String[] addrWhereParams = new String[]{id,
	         		Cursor addrCur = cr.query(ContactsContract.Data.CONTENT_URI,
	         	                null, null, null, null);
	         		while(addrCur.moveToNext()) {
	         			String poBox = addrCur.getString(
	         	 		String street = addrCur.getString(
	         	 		String city = addrCur.getString(
	         	 		String state = addrCur.getString(
	         	 		String postalCode = addrCur.getString(
	         	 		String country = addrCur.getString(
	         	 		String type = addrCur.getString(

	         	 		// Do something with these....


	         	 	// Get Instant Messenger.........
	         	 	String imWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
	         	 	String[] imWhereParams = new String[]{id,
	         	 	Cursor imCur = cr.query(ContactsContract.Data.CONTENT_URI,
	         	            null, imWhere, imWhereParams, null);
	         	 	if (imCur.moveToFirst()) {
	         	 	    String imName = imCur.getString(
	         	 	    String imType;
	         	 	    imType = imCur.getString(

	         	 	// Get Organizations.........

	         	 	String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
	         	 	String[] orgWhereParams = new String[]{id,
	         	 	Cursor orgCur = cr.query(ContactsContract.Data.CONTENT_URI,
	         	                null, orgWhere, orgWhereParams, null);
	         	 	if (orgCur.moveToFirst()) {
	         	 		String orgName = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA));
	         	 		String title = orgCur.getString(orgCur.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE));


Note : Make sure you add this permission to the AndroidManifest File.

Download the complete android java source code from the link below.

Posts to come ……..

How to add and delete contacts programatically. keep visiting coderzheaven….

Some of the posts you want to see are located here
Please leave your valuable comments on this post.

23 thoughts on “Get All Details from Contacts in ANDROID.”

  1. The ONLY resource that worked. I’ve been Googling this problem for days. Most useful and accurate “tutorial”, if you will.

    Thank you.

  2. hi,I am using your code to get contacts of android.i am taking the contact no.and name but it works very slow on real device.the screen turns black and then shows the contact after a while.
    what is the problem.please help me

  3. But with this code u program run very slowly i had run 1 contacts with 348 contact not full details, this code take > 1m. How to improve effective? I need idea! thanks.

    1. Hi Lance :-
      Check this line
      String phone = pCur.getString( pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      System.out.println(“phone” + phone); // printing the phone number-> check Logcat

  4. great tutorial…..
    I am getting all contact from the phone, after that i display only number to textview, first time i pick the contact and can display to the textview.then getting another contact, but it cannot be change the previous selected one. always show the first selected contact.
    Plz help me, Thanks in advance……….

  5. hi myself praveen

    i lost my mobile last week i need the all contacts # when i was using WIFI the contacts will synchronization to mail. There is any way is there to get my contacts through mail id

    Please contact to mail :

    contact : 9916594114


  6. hi.
    my language is not English.
    I want to learn android program.
    I need cods that send contacts to email.
    can you help me?
    thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>