1

I'm able to retrieve the display name of contact using the id Code as follows:

Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, selectedid);
Cursor cur = managedQuery(uri, null, null, null, null);
startManagingCursor(cur);
cur.moveToNext();
String mname = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

Where the "selectedid" is my id of the contact to be retrieved. Now i have a problem in retrieving the phone number from that id.

If possible can u type me the code which i have to add to get the phone number from that id

Janusz
  • 187,060
  • 113
  • 301
  • 369
kAnNaN
  • 3,669
  • 4
  • 28
  • 39
  • possible duplicate of [Retrieve Contact Phone Number From URI in Android](http://stackoverflow.com/questions/3370628/retrieve-contact-phone-number-from-uri-in-android) – Valentin Rocher Feb 08 '11 at 15:16

2 Answers2

1

Have you tried:

String number = cur.getString(cur.getColumnIndex(
    ContactsContract.CommonDataKinds.Phone.NUMBER));
Sebastian Roth
  • 11,344
  • 14
  • 61
  • 110
  • i have tried it and got a error stating..... "02-08 14:18:42.722: ERROR/AndroidRuntime(415): java.lang.RuntimeException: Unable to resume activity {com.kpj4s.as/com.kpj4s.as.activity_newsms}: java.lang.IllegalStateException: get field slot from row 0 col -1 failed" – kAnNaN Feb 08 '11 at 08:49
0

i kind of figured it out .... try the link bellow...

Retrieve Contact Phone Number From URI in Android

Community
  • 1
  • 1
kAnNaN
  • 3,669
  • 4
  • 28
  • 39