0

我目前正在開發一個android應用程序,它要求我讀取設備上的所有聯繫人,並根據條件僅選擇特定的聯繫人(僅限具有至少一個有效手機號碼的聯繫人和與該聯繫人鏈接的所有電子郵件地址)。android:讀取特定的聯繫信息

從我試過推薦的方法https://stackoverflow.com/a/19563999/3262731,但在約800個聯繫人的測試設備上,檢索所有記錄,然後過濾大約需要17-20秒。

理想情況下,我很想建立一個查詢條件,將聯繫人數據庫中的聯繫人,電話和電子郵件存儲表連接起來,而不是在我的代碼中進行過濾。

有沒有人有任何建議嗎?

非常感謝!

回答

0

根據http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html

查詢

If you need to read an individual contact, consider using CONTENT_LOOKUP_URI instead of CONTENT_URI. 
    If you need to look up a contact by the phone number, use PhoneLookup.CONTENT_FILTER_URI, which is optimized for this purpose. 
    If you need to look up a contact by partial name, e.g. to produce filter-as-you-type suggestions, use the CONTENT_FILTER_URI URI. 
    If you need to look up a contact by some data element like email address, nickname, etc, use a query against the ContactsContract.Data table. The result will contain contact ID, name etc. 
+0

感謝Drakosha,但我想做的是不查找聯繫人 - 我想根據他們是否至少有一個手機號碼檢索所有聯繫人(第一,姓氏和手機號碼),並檢索所有他們的電子郵件地址。 – thisguy 2014-08-30 15:26:09

0

的Android文檔似乎包含在你在找什麼發現here信息。

private static final String[] PROJECTION = 
    { 
     /* 
     * The detail data row ID. To make a ListView work, 
     * this column is required. 
     */ 
     Data._ID, 
     // The primary display name 
     Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
       Data.DISPLAY_NAME_PRIMARY : 
       Data.DISPLAY_NAME, 
     // The contact's _ID, to construct a content URI 
     Data.CONTACT_ID 
     // The contact's LOOKUP_KEY, to construct a content URI 
     Data.LOOKUP_KEY (a permanent link to the contact 
    }; 

return new CursorLoader(getActivity(), contentUri, PROJECTION, SELECTION, SELECTION_ARGS, SORT_ORDER); 

有關如何在文檔中定義標準的更多詳細信息。我認爲這會比使用ContentResolver更快。

+0

謝謝尼爾森,那是我的出發點,但它並不完全符合我的要求,而且文檔本身並沒有提供很多線索來同時從不同的聯繫表(電子郵件,電話)獲取數據。 – thisguy 2014-08-30 15:27:45