我正在尝试在我的Android应用程序中执行以下查询:
private static final String[] PROJECTION =
{
Data.CONTACT_ID, Data.MIMETYPE,
Data.DISPLAY_NAME, Phone.NUMBER,
Phone.TYPE, StructuredName.GIVEN_NAME,
StructuredName.MIDDLE_NAME,
StructuredName.FAMILY_NAME,
Data.DELETED
};
private static final String SELECTION = "(" + Data.MIMETYPE + " = ? AND "
+ Phone.TYPE + " IN (?,?,?)) OR ("
+ Data.MIMETYPE + " IN (?))";
private static final String[] SELECTION_ARGS =
{
Phone.CONTENT_ITEM_TYPE,
String.valueOf(Phone.TYPE_MOBILE),
String.valueOf(Phone.TYPE_HOME),
String.valueOf(Phone.TYPE_WORK),
StructuredName.CONTENT_ITEM_TYPE
};
final Cursor cursor = mContext.getContentResolver().query(
Data.CONTENT_URI, PROJECTION, SELECTION, SELECTION_ARGS, Data.CONTACT_ID);
但是我收到以下错误:
04-29 11:00:58.715 8588 15565 E DatabaseUtils: Writing exception to parcel 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: java.lang.IllegalArgumentException: Invalid column deleted 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.database.sqlite.SQLiteQueryBuilder.computeProjection(SQLiteQueryBuilder.java:632) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.database.sqlite.SQLiteQueryBuilder.buildQuery(SQLiteQueryBuilder.java:447) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:387) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at com.android.providers.contacts.ContactsProvider2.doQuery(ContactsProvider2.java:6528) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at com.android.providers.contacts.ContactsProvider2.queryLocal(ContactsProvider2.java:6479) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:5038) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.content.ContentProvider$Transport.query(ContentProvider.java:238) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112) 04-29 11:00:58.715 8588 15565 E
DatabaseUtils: at android.os.Binder.execTransact(Binder.java:453)
我想知道我正在阅读的联系人是否被删除,因此我需要Data.DELETED列,这似乎导致错误。 但是当我检查Android documentation时,DELETED似乎是一个与ContactsContract.Data一起使用的有效列。
答案 0 :(得分:0)
如How do implicit joined columns work with Android contacts data?中所述,将URI更改为ContactsContract.RawContactsEntity.CONTENT_URI
似乎有效。