如何从游标对象获取URL

时间:2020-12-21 08:40:16

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

我有一个Cursor指向联系人。如何从该Cursor构建一个url?

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

我需要知道,因为从这里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:

我需要一个网址,以便我可以建立一个手机uri,像这样:

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

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

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

我可以查询该联系人的所有电话号码。

1 个解决方案

#1


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();

#1


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();