2011-09-06 80 views
0

我有捆綁使用下面的代碼並非所有的聯繫人返回

getContentResolver().query(uri, null, null, null, null) 

讓所有的聯繫人,但它不會返回所有聯繫人。它似乎只返回列「single_is_restricted」值爲「1」的聯繫人,但該列不能從應用程序中斷言,當我通過sqlite直接查看錶「contacts」時發現它。

我如何獲取所有聯繫人?

謝謝。

+2

你使用了什麼'uri'? – Michael

回答

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); 
} 

如果你能得到一個異常(比如你可以選擇變化......),你可以從日誌貓日誌貓得到圖/表名,像這樣的(你可以看到「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' 

Check view;

.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的行。

[對不起我的英文]

0

一些廠商如三星與Facebook的交易中,Facebook的同步與姓名,電話,圖片等設備聯繫人,但這些聯繫人無法通過聯繫人進行訪問蜜蜂。

這就是您的應用程序無法訪問某些聯繫人,但在聯繫人應用程序中可見的原因。

相關問題