如何从游标对象获取URL

时间:2009-06-16 17:28:53

标签: android

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

我需要知道,因为从这里开始 http://developer.android.com/guide/topics/providers/content-providers.html

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

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

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

1 个答案:

答案 0 :(得分:1)

您可以使用以下查询来检索特定联系人的所有号码:

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