0

我一直在尝试使用 ContactsContract 获取所有联系人。我想使用“选择”参数过滤结果。换句话说,我想检索所有以字母 A 开头的联系人。所以我写了这个片段。但它崩溃了。

Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] {
        Contacts._ID, // the contact id column
        Contacts.DISPLAY_NAME,  // column if this contact is deleted
        Contacts.HAS_PHONE_NUMBER   };

String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + 
            " COLLATE LOCALIZED ASC";
cursor = getContentResolver().query
            (uri,
            projection,
            "android.provider.ContactsContract.Contacts.DISPLAY_NAME like 'A'",
            null,
            sortOrder);

据我所知,我可以插入到选择参数中,就像你可以在 SQL 语句的 where 子句中插入一样,这就是我所做的。

4

1 回答 1

0

干得好。

db.query(
  TABLE_NAME,
  projection, 
  Contacts.DISPLAY_NAME + " like " + "'?%'",
  new String[] { "A" },
  null, null, null
);
于 2012-06-21T11:07:51.713 回答