tags:

views:

78

answers:

1

Hi,

I have a Cursor points to a Contact. How can I get an url built from that Cursor?

I need to know that because from here http://developer.android.com/guide/topics/providers/content-providers.html

I need to have an url so that I can build a phone uri, like this:

phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);

and I can query all the phone numbers for that contact.

A: 

You can use the following query to retrieve all numbers for a certain contact:

/* the following line assumes that the contactCursor you described
 * has the People._ID column at index 0 in its projection. */
int contactId = contactCursor.getInt(0);

Cursor numberCursor = getContentResolver().query(Phones.CONTENT_URI,
  new String[] {Phones.NUMBER}, Phones.PERSON_ID + "=" + contactId, null, null);
while(cursor.moveToNext()) {
  String number = cursor.getString(0);
}
cursor.close();
Josef