0

I have a string content//com.android.contacts/contacts/contacts/2 ie aft the user has selected a particular number.

From this string, how do i get the phone number of this particular contact?

I am new to android environment, so my question might seem a bit primitive.

Cursor c = (Cursor)mAdapter.getItem(a.keyAt(i));
Long id = c.getLong(c.getColumnIndex(ContactsContract.Contacts._ID));
contacts.add(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id));

chosenContacts = sb.toString();

chosenContacts is my string and that contains content//com.android.contacts/contacts/contacts/2

Juliano Alves
  • 2,006
  • 4
  • 35
  • 37
Hermoine
  • 1
  • 1
  • does your string contain a number like String str = "asdsad 999999999";? – Raghunandan May 01 '13 at 14:04
  • I have made the changes.. I need to get the phone number from it now.. How do I do it?? – Hermoine May 01 '13 at 14:10
  • check the link http://stackoverflow.com/questions/4613104/how-to-retrieve-contact-name-and-phone-number-in-android – Raghunandan May 01 '13 at 14:11
  • the number 2 in "content//com.android.contacts/contacts/contacts/2" is the ID right?? Isn there any function that can get me the phone number from the ID??? – Hermoine May 01 '13 at 14:17

1 Answers1

0

You need a second request. You can use the id of your snippet for it:

     Cursor phoneNoCursor = contentResolver.query(
             Data.CONTENT_URI,
             new String[] {Phone.NUMBER, Phone.TYPE, Phone.LABEL},
             Data.MIMETYPE + " = ? AND " + Data.CONTACT_ID + " = ? ",
             new String[] {String.valueOf(Phone.CONTENT_ITEM_TYPE, id)}, 
             null);

For the list of possible types see the description of the Phone class. But maybe the number itself and its label are enough anyway.

Wolfram Rittmeyer
  • 2,402
  • 1
  • 18
  • 21