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. SKD 1.6 no available package for API 1


I have installed the new SDK 1.6r1 on Windows and I realise that 1.6
does not included the older APIs so ran the android.bat tool to
download them.

The "available packages" only offer me SDK Platform Android 1.1 API 2;
I was also hoping to download 1.0 API 1 as I am developing an
application that only needs very basic functionality and I would like
to be compatible with as many devices as possible.



2. One issue left before i start to really use my HERO

Hello! This Monday i went and got a HTC Hero.
Have fixed with to and from the whole week, and are now starting to
get it like I want it with the right software, root, recent ROM, etc.

I have used much of the week to search around the forums for one thing
I can not possibly get to work.

I have a Nokia BH-602 which I previously used with my E75 (or because
of this issue is still using)
Now the problem.
Paired with my E75, I got all notifications of BH-602, ex. sms, msn,
mms, email etc, all the sounds that the phone did, even custom
In my HTC Hero it is the only conversations that I can get the BH-602,
and to be honest, that is the least used function for me. :-)

WHY ?!?!?!

No, BH-602 is not an A2DP headset.

If that is the case that Nokia has had this to work with just BT1.5,
why not the android? Or why there is not a SINGLE little answer
somewhere on the net that says more than "it does not, you must have
It's not needed because it works with my nokia.
Even a single small ugly hack or something, anything!

I want my hero, for which Eddie Izzard says;

"This is the one! I will not have to work again!"

Help please anyone, if nothing else, a laugh a little at Izzard, so


3. Why do my team makes integration part for developing Android?

4. "singleTask" really always at the root of activity stack?

5. How can I extends InputMethodService and using its feature without setting system keyboard??

6. Issue of selection 3D vertex (gluUnProject)

7. Help: I can't click on an Animated View