我有一些代码可以查询联系人数据库,如下所示: -
Uri uri = ContactsContract.Groups.CONTENT_SUMMARY_URI;
String[] projection = new String[] {
ContactsContract.Groups._ID,
ContactsContract.Groups.TITLE,
ContactsContract.Groups.SUMMARY_WITH_PHONES,
};
String selection = ContactsContract.Groups.SUMMARY_WITH_PHONES + ">0";
if (Version.androidVersion() <= 15) selection += " AND " + ContactsContract.Groups.GROUP_VISIBLE + "=1";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Groups.TITLE + " COLLATE LOCALIZED ASC";
return new CursorLoader(r.activity, uri, projection, selection, selectionArgs, sortOrder);
在相当多的设备上,它已经运行了很长时间。我今天在新的华为P8(Android 7.0)上测试它,它失败了:
Caused by: java.lang.IllegalArgumentException: Invalid column summ_phones
现在,summ_phones
是与ContactsContract.Groups.SUMMARY_WITH_PHONES
(Android source code)相关联的字符串。事实上,如果我拿出引用,那么代码就会停止崩溃。我找不到对此选项的引用。
我错过了什么?如何使查询起作用?