以下查询在我的设备(API 15)上运行良好。它在我运行 API 8 或 API 10 的模拟器中不起作用。
这是查询:
Cursor contactsCur = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Data._ID,
ContactsContract.Data.CONTACT_ID,
ContactsContract.Data.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Organization.COMPANY,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.Data.LOOKUP_KEY,
ContactsContract.CommonDataKinds.Phone.NUMBER,
Contacts.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Phone.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredPostal.CITY,
ContactsContract.CommonDataKinds.StructuredPostal.STREET,
ContactsContract.CommonDataKinds.StructuredPostal.REGION,
ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE},
ContactsContract.Data.HAS_PHONE_NUMBER + " >? ",
new String[] { "0" },
ContactsContract.Data.DISPLAY_NAME + " COLLATE NOCASE ASC");
这是它抛出的异常:
android.database.sqlite.SQLiteException: no such column: has_phone_number: , while compiling: SELECT _id, contact_id, display_name, data1, data2, lookup, data1, mimetype, mimetype, data7, data4, data8, data9 FROM view_data_restricted data WHERE (1) AND (has_phone_number >? ) ORDER BY display_name COLLATE NOCASE ASC
奇怪的是,以下代码也不起作用:
Cursor contactsCur = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] { ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER},
ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER + " >? ",
new String[] { "0" },
null);
它产生:java.lang.IllegalArgumentException: Invalid column has_phone_number
http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html声明可以ContactsContract.CommonDataKinds.Phone
访问HAS_PHONE_NUMBER
From 接口 android.provider.ContactsContract.ContactsColumns
更奇怪的是,这个查询有效:
Cursor contactsCur = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Data.LOOKUP_KEY},
null,
null,
null);
但是这个没有:
Cursor contactsCur = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Data.HAS_PHONE_NUMBER},
null,
null,
null);
ContactsContract.Data.LOOKUP_KEY
来自与ContactsContract.Data.HAS_PHONE_NUMBER
!相同的隐式连接
我哪里错了?