ContentProvider (contacts) - no such column: metadata_dirty

為{幸葍}努か 提交于 2019-12-11 06:54:08

问题


I'm trying to get all contacts of a specific type from the phone like following:

Cursor cursor = context.getContentResolver().query(
            ContactsContract.RawContacts.CONTENT_URI,
            null,
            ContactsContract.RawContacts.ACCOUNT_TYPE + "='com.whatsapp'",
            null,
            ContactsContract.RawContacts.CONTACT_ID + " ASC");

But this line already throws an exception (custom rom, nougat => maybe it's related to this?). I only got this error from one user yet and I'm stuck here, does anyone know how to solve that? Is there an alternative way to query all contacts?

My exception looks like following:

Exception: android.database.sqlite.SQLiteException: no such column: metadata_dirty (code 1): , while compiling: 
SELECT sort_key, send_to_voicemail, pinned, display_name, metadata_dirty, 
phonebook_label_alt, version, phonebook_bucket, _id, custom_ringtone, 
times_contacted, account_type_and_data_set, sync4, dirty, sync2, 
contact_id, raw_contact_is_user_profile, aggregation_mode, data_set,
phonebook_label, account_type, sync3, display_name_alt, phonetic_name,
last_time_contacted, display_name_source, backup_id, sort_key_alt, 
phonebook_bucket_alt, deleted, starred, account_name, sync1, sourceid, 
phonetic_name_style 
FROM view_raw_contacts_restricted AS view_raw_contacts 
WHERE (1) 
AND ((account_type='com.whatsapp')) 
ORDER BY contact_id ASC
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java)
    at android.content.ContentResolver.query(ContentResolver.java)
    at android.content.ContentResolver.query(ContentResolver.java)
    ...

回答1:


I don't see anything wrong with your query, it seems like this is an internal bug in the user's custom ROM.

METADATA_DIRTY is a new column in Android N: https://developer.android.com/reference/android/provider/ContactsContract.RawContactsColumns.html#METADATA_DIRTY

So it seems like the system is Nougat, but the Contacts DB is based on an older version of Android.



来源:https://stackoverflow.com/questions/41868397/contentprovider-contacts-no-such-column-metadata-dirty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!