How to get Contact information in array

by Arsalan » Fri, 14 Jan 2011 21:15:03 GMT

Sponsored Links
 Im new to android development, im trying to retrieve contact list with
there name and phone numbers.i try following code :

 // Get a cursor over every contact.
  Cursor cursor = getContentResolver().query(People.CONTENT_URI,null,
null, null, null);
   // Let the activity manage the cursor lifecycle.
     // Use the convenience properties to get the index of the
  int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
     int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);
    String[] result = new String[cursor.getCount()];
  if (cursor.moveToFirst())
    do {
       // Extract the name.
       String name = cursor.getString(nameIdx);
        // Extract the phone number.
       String phone = cursor.getString(phoneIdx);
      result[cursor.getPosition()] = name + "-" +" "+  phone;
     } while(cursor.moveToNext());

this code should return an array with the all contacts name and its
phone number but this only return name of the contact and return NULL
in phone number,

Example Output:

 John - null

Please help me in this regards thats whats wrong in this code. Any
help in this regards will highly apreaciated, and its urgent thanks in


Re: How to get Contact information in array

by Kumar Bibek » Fri, 14 Jan 2011 21:19:29 GMT

 Either you are not using the right column, or you don't have any phone
number for John.

Morever, this class is deprecated, and it might not work properly on
emulators/devices beyond 1.5. Use ContactsContract instead.
Kumar Bibek 


Sponsored Links

Other Threads

1. Fwd: How to disallow task switching

Hi All,
How to disallow task switching? It is possible

---------- Forwarded message ----------
From: DAVIDT <>
Date: 2009/12/8
Subject: How to disallow task switching
To: Android Developers <>

Hi All,
How to disallow task switching? It is possible


2. How to navigate between different screens


I am a Symbian Application developer and now i am moving to Android.
So need some little help from you guys.
I want to make an application which will have two screens and those
two screens will have different attributes. Now on clicking on one
button in one screen I want to go to the next screen and also i shud
have a facility to go back to my original screen.

Therer are number of places where I have to make changes what i
believe. So i need a proper guidance regarding these so that in
feature I can add as number of screens as i want and at the same time
i can navigate through them

Any help on this will be great for me.



3. Android keeps rebooting

4. Send zip file as mail attachment

5. locationManager.requestLocationUpdates and 1.6

6. How getting an APK's signature outside of Android (e.g. with jarsigner or another tool)

7. Project dependency: reusing code and resources from another Android project