本文介绍了Android的API 8,10 ContactsContract.Data.HAS_PHONE_NUMBER没有这样的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的查询运行良好,我的设备(API 15)上。运行API 8或10 API在我的模拟器这是行不通的。

The below query runs fine on my device (API 15). It does not work in my emulator running API 8 or 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:没有这样的列:has_phone_number:在编制:选择_id,CONTACT_ID,DISPLAY_NAME,数据1,数据2,查询,数据1,MIMETYPE,MIMETYPE,DATA7,DATA4,DATA8,DATA9从view_data_restricted数据,其中(1)和(has_phone_number>?)ORDER BY DISPLAY_NAME COLLATE NOCASE ASC

Here is the exception that it throws: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

奇怪的是,以下code也不起作用:

Strangely enough, the following code also does not work:

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:如果无效的列has_phone_number

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html指出 ContactsContract.CommonDataKinds.Phone 有权访问 HAS_PHONE_NUMBER 从接口android.provider.ContactsContract.ContactsColumns

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html states that ContactsContract.CommonDataKinds.Phone has access to HAS_PHONE_NUMBER From interface android.provider.ContactsContract.ContactsColumns

要添加到陌生感,这个查询工作:

To add to the strangeness, this query works:

Cursor contactsCur = getContentResolver().query(
    ContactsContract.Data.CONTENT_URI,
    new String[] { ContactsContract.Data.LOOKUP_KEY},
    null,
    null,
    null);

不过,这一次没有:

But this one does not:

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

ContactsContract.Data.LOOKUP_KEY comes from the same implicit join as ContactsContract.Data.HAS_PHONE_NUMBER !

我在哪里去了?

推荐答案

您正在运行到的主要问题是, ContactsContract.CommonDataKinds.Phone.CONTENT_URI 自动 has_​​phone_number = 1 过滤器。所以,你可以得到保证,一切都现身 Phone.CONTENT_URI的确实的有一个电话号码。然后,您可以进一步筛选下来通过检查 Phone.TYPE Phone.TYPE_MOBILE 中的一个或 Phone.TYPE_WORK_MOBILE (例如),如果要限制它有什么样的电话号码。

The main problem you're running into is that ContactsContract.CommonDataKinds.Phone.CONTENT_URI automatically filters on has_phone_number=1. So you can be guaranteed that everything coming out of Phone.CONTENT_URI does have a phone number. You can then filter that down further by checking if Phone.TYPE is one of Phone.TYPE_MOBILE or Phone.TYPE_WORK_MOBILE (for example) if you want to restrict what type of phone number it has.

有关引用(注意, has_​​phone_number 数据/电话缺席 URI):

For reference (note that has_phone_number is absent from the data/phones URI):

Columns for content://com.android.contacts/contacts:
- times_contacted
- contact_status
- custom_ringtone
- has_phone_number
- phonetic_name
- phonetic_name_style
- contact_status_label
- lookup
- contact_status_icon
- last_time_contacted
- display_name
- sort_key_alt
- in_visible_group
- _id
- starred
- sort_key
- display_name_alt
- contact_presence
- display_name_source
- contact_status_res_package
- contact_status_ts
- photo_id
- send_to_voicemail

Columns for content://com.android.contacts/data/phones:
- data_version
- phonetic_name
- phonetic_name_style
- contact_id
- lookup
- data12
- data11
- data10
- mimetype
- data15
- data14
- data13
- display_name_source
- data_sync1
- data_sync3
- data_sync2
- data_sync4
- account_type
- custom_ringtone
- status
- data1
- data4
- data5
- data2
- data3
- data8
- data9
- group_sourceid
- data6
- account_name
- data7
- display_name
- in_visible_group
- display_name_alt
- contact_status_res_package
- is_primary
- contact_status_ts
- raw_contact_id
- times_contacted
- contact_status
- status_res_package
- status_icon
- contact_status_icon
- mode
- version
- last_time_contacted
- res_package
- _id
- name_verified
- status_ts
- dirty
- is_super_primary
- photo_id
- send_to_voicemail
- name_raw_contact_id
- contact_status_label
- status_label
- sort_key_alt
- starred
- sort_key
- contact_presence
- sourceid

这篇关于Android的API 8,10 ContactsContract.Data.HAS_PHONE_NUMBER没有这样的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:37