我通过使用以下代码
来获取所有联系人getContentResolver().query(uri, null, null, null, null)
但它不会返回所有联系人。它似乎只返回列“single_is_restricted”值为“1”的联系人,但是这个列无法从aplication中找到,我在直接通过sqlite查看表“contacts”时发现了它。
我如何获得所有联系人?
感谢。
答案 0 :(得分:1)
检查表/视图的create语句。
例如,在ContactManager示例中,您将看到此代码块;
private Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
(mShowInvisible ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
如果您可以获得异常(例如,您可以更改选择...),您可以从log cat获取视图/表名,就像这样(您可以在log cat中看到“ASDF”,只是获得异常) ;
04-28 12:16:34.682: E/AndroidRuntime(466): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.contactmanager/com.example.android.contactmanager.ContactManager}: android.database.sqlite.SQLiteException: near "'1'": syntax error: , while compiling: SELECT _id, display_name FROM view_contacts_restricted WHERE (in_visible_group =ASDF '1') ORDER BY display_name COLLATE LOCALIZED ASC
点是; FROM view_contacts_restricted
现在您可以查看此视图的create语句。您可以安装根浏览器应用程序。并将sqlite文件复制到SDCARD或将sqlite3安装到Android设备。然后从命令行打开数据库;
sqlite3 '/home/semeteycoskun/Desktop/contacts2.db'
检查视图;
.schema view_contacts_restricted
结果是;
CREATE VIEW view_contacts_restricted
AS SELECT contacts._id AS _id
, contacts.custom_ringtone AS custom_ringtone
, name_raw_contact.display_name_source AS display_name_source
, name_raw_contact.display_name AS display_name
, name_raw_contact.display_name_alt AS display_name_alt
, name_raw_contact.phonetic_name AS phonetic_name
, name_raw_contact.phonetic_name_style AS phonetic_name_style
, name_raw_contact.sort_key AS sort_key
, name_raw_contact.sort_key_alt AS sort_key_alt
, name_raw_contact.sort_priority AS sort_priority
, name_raw_contact.sort_priority_alt AS sort_priority_alt
, name_raw_contact.sort_locale AS sort_locale
, name_raw_contact.sort_locale_alt AS sort_locale_alt
, name_raw_contact.contact_in_visible_group AS in_visible_group
, has_phone_number, lookup, photo_id
, contacts.last_time_contacted AS last_time_contacted
, contacts.send_to_voicemail AS send_to_voicemail
, contacts.starred AS starred
, contacts.times_contacted AS times_contacted
, status_update_id
, dirty_contact
, has_email
, link_count
, raw_contact_linkpriority1
, link_type1
, raw_contact_linkpriority2
, link_type2
, raw_contact_linkpriority3
, link_type3
, raw_contact_linkpriority4
, link_type4
, raw_contact_linkpriority5
, link_type5
FROM contacts
JOIN raw_contacts AS name_raw_contact ON(name_raw_contact_id=name_raw_contact._id)
WHERE single_is_restricted=0;
如果create语句包含single_is_restricted = 0,则无法访问single_is_restricted = 1的行。
[对不起我的英文]
答案 1 :(得分:0)
像三星这样的制造商与Facebook达成交易,其中Facebook与设备联系人与姓名,电话,图片等同步,但这些联系人无法通过联系人API访问。
这是您的应用无法访问某些联系人的原因,但在股票联系人应用中可以看到。