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
http://techdroid.kbeanie.com
http://www.kbeanie.com



On Fri, Jan 7, 2011 at 3:27 PM, Arsalan <[email protected]> wrote:

> 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.
>     startManagingCursor(cursor);
>     // Use the convenience properties to get the index of the
> columns
>  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
> advance.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to