下面的查询运行我的设备(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
从接口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
!
我要去哪里错了?