获取所有联系人和他们的详细信息(如地址)在一个OUTER JOIN查询他们的、详细信息、地址、JOIN

2023-09-07 16:40:04 作者:偷鱼罐头的猫

我知道如何检索特定联系人的联系人数据。但是,我不能找到一个办法让所有联系人加上他们的一些细节在一个单一的查询。下面code得到所有联系人为邮寄地址:

I know how to retrieve contact data for specific contacts. However, i can't find a way to get all contacts plus some of their details in a single query. The following code gets all contacts having a postal address:

  Uri uri = ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI;
  String[] projection = new String[] {
    StructuredPostal._ID,
    StructuredPostal.LOOKUP_KEY,
    StructuredPostal.DISPLAY_NAME,
    StructuredPostal.STREET,
    StructuredPostal.CITY
  };
  String sortOrder = StructuredPostal.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
  Cursor c = getContentResolver().query(uri, projection, null, null, sortOrder);

但我需要的是所有联系人,他们是否有地址或者不是。这是可行的使用ContatsContract API,或者我需要创建自定义的外部连接查询?如何任何提示?

But what i need are all contacts, whether they have postal address or not. Is this doable using the ContatsContract API, or do i need to create custom outer join query? Any hints on how?

推荐答案

在Android 2.0的所有联系人信息存储在一个数据库中的表。所以,你可以得到所有的信息,你需要在一个单一的查询:

All contact information in Android 2.0 is stored in a single database table. So you can get all the information you need in a single query:

Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
    null, null, null, sortOrder);

刚刚遍历数据,并检查 Data.MIMETYPE 列。例如,如果此列 StructuredPostal.CONTENT_ITEM_TYPE 值,那么你可以从这个列获得 StructuredPostal 字段。

The just iterate through the data and check Data.MIMETYPE column. For example, if this column has StructuredPostal.CONTENT_ITEM_TYPE value, then you can get StructuredPostal fields from this column.