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. How to implement FADE effect in background of ListView?

There's no need to use a GradientDrawable, that effect is provided by
the View class. Look for the various occurrences of "fade" in the
documentation of View. ListView in particular enables this by default.


2. hint for those using nx1, miley or eclair os *multi email accounts enabled gituh maksudnya*

as subject :)
kan banyak neh, yg udah pake n1, miley dan os eclair *ini os 2 ya yg bisa
multi email?*
yg multi gmail accounts :)
ada hint neh.
pada punya kan email account yg di host di google? kayak yg saya misalnya,
milis(@) hosted di google.....
nah, tinggal add account di gmail, dah gt masukin password...see what happen
i LOVE it!

*kalo basi...yah uwes lah, maklum, dapet n1nya juga teulad*

*ngeloyor ke dalem kaleng ijo*

3. Upgrade SPL Magic 32A 1.33.0009 ke latest

4. Where can I download "Android SDK source code" ?

5. About Sqlite Database

6. Clicking ItemizedItem

7. Understand Device deep sleep behavior and its affect on the application.