2014-06-28 71 views
3
public static String getContactName(Context context, String id, String address){ 

     if(id==null){ 
      if(address==null){ 
       return null; 
      }else{ 
       return PhoneNumberUtils.formatNumber(address); 
      } 
     } 

     Cursor cursor = context.getContentResolver().query(
       ContactsContract.Data.CONTENT_URI, 
       null, 
       null, 
       null, 
       null); 

     if(cursor!=null){ 
      try{ 
       if(cursor.moveToFirst()){ 
        do{ 
         for(int i=0;i<cursor.getColumnCount();++i){ 
          String columnName = cursor.getColumnName(i); 
          String columnText = cursor.getString(i); 
          Log.d(columnName, columnText==null ? "null":columnText); 
         } 
         Log.d("endline","***************************"); 
        }while(cursor.moveToNext()); 


       }else{ 
        Log.d("cursor", "not greater than 0"); 
       } 
      }finally{ 
       cursor.close(); 
      } 
     } 

     if(address != null){ 
      return PhoneNumberUtils.formatNumber(address); 
     } 

     return "just testing shit"; 
    } 

所以我的問題是,當我回到我的所有聯繫人我得到每個聯繫人的多個副本同一聯繫人的多個副本,我不知道爲什麼,或什麼做這件事。我在這裏查看了我的聯繫人:https://www.google.com/contacts/#contactsAndroid通訊錄內容提供商返回聯繫人沒有重複的聯繫人

以及從手機中刪除所有聯繫人並重新發送到谷歌聯繫人以確保沒有重複。我無法理解發生了什麼,儘管我可能只是以某種方式愚蠢。

這裏是輸出的樣子(截斷幾個觸點)

第一招:

第二個
sort_key: James LaChance 
photo_uri: null 
status_label: null 
status_ts: null 
status_res_package: null 
name_verified: 0 
display_name: James LaChance 
last_time_used: null 
mimetype: vnd.android.cursor.item/photo 
phonebook_label_alt: L 
data6: null 
version: 3 
photo_id: null 
data3: null 
custom_ringtone: null 
times_contacted: 0 
account_type_and_data_set: com.google 
dirty: 0 
data7: null 
data15: null 
raw_contact_is_user_profile: 0 
data_set: null 
phonebook_label: J 
data10: null 
res_package: null 
account_type: com.google 
data11: null 
display_name_alt: LaChance, James 
lookup: 3448i1629e6890832873d 
phonetic_name: null 
last_time_contacted: 0 
contact_last_updated_timestamp: 1403954657613 
data13: null 
in_visible_group: 1 
chat_capability: null 
data9: null 
data_sync1: https://www.google.com/m8/feeds/photos/media/jmsmaupin1%40gmail.com/1629e6890832873d 
sort_key_alt: LaChance, James 
contact_presence: null 
data_version: 0 
phonetic_name_style: 0 
name_raw_contact_id: 1 
raw_contact_id: 1 
send_to_voicemail: 0 
data4: null 
data12: null 
contact_status: null 
contact_status_label: null 
pinned: 2147483647 
status_icon: null 
status: null 
data1: null 
phonebook_bucket: 10 
data_sync2: null 
contact_status_res_package: null 
in_default_directory: 1 
_id: 1 
is_super_primary: 0 
data5: null 
contact_id: 8 
data8: null 
is_primary: 0 
data_sync4: 0 
has_phone_number: 1 
display_name_source: 40 
photo_file_id: null 
data_sync3: null 
data14: null 
contact_status_ts: null 
phonebook_bucket_alt: 12 
mode: null 
data2: null 
group_sourceid: null 
starred: 0 
photo_thumb_uri: null 
times_used: null 
contact_status_icon: null 
contact_chat_capability: null 
sourceid: 1629e6890832873d 

sort_key: James LaChance 
photo_uri: null 
status_label: null 
status_ts: null 
status_res_package: null 
name_verified: 0 
display_name: James LaChance 
last_time_used: null 
mimetype: vnd.android.cursor.item/name 
phonebook_label_alt: L 
data6: null 
version: 3 
photo_id: null 
data3: LaChance 
custom_ringtone: null 
times_contacted: 0 
account_type_and_data_set: com.google 
dirty: 0 
data7: null 
data15: null 
raw_contact_is_user_profile: 0 
data_set: null 
phonebook_label: J 
data10: 1 
res_package: null 
account_type: com.google 
data11: 0 
display_name_alt: LaChance, James 
lookup: 3448i1629e6890832873d 
phonetic_name: null 
last_time_contacted: 0 
contact_last_updated_timestamp: 1403954657613 
data13: null 
in_visible_group: 1 
chat_capability: null 
data9: null 
data_sync1: null 
sort_key_alt: LaChance, James 
contact_presence: null 
data_version: 0 
phonetic_name_style: 0 
name_raw_contact_id: 1 
raw_contact_id: 1 
send_to_voicemail: 0 
data4: null 
data12: null 
contact_status: null 
contact_status_label: null 
pinned: 2147483647 
status_icon: null 
status: null 
data1: James LaChance 
phonebook_bucket: 10 
data_sync2: null 
contact_status_res_package: null 
in_default_directory: 1 
_id: 2 
is_super_primary: 0 
data5: null 
contact_id: 8 
data8: null 
is_primary: 0 
data_sync4: 10 
has_phone_number: 1 
display_name_source: 40 
photo_file_id: null 
data_sync3: null 
data14: null 
contact_status_ts: null 
phonebook_bucket_alt: 12 
mode: null 
data2: James 
group_sourceid: null 
starred: 0 
photo_thumb_uri: null 
times_used: null 
contact_status_icon: null 
contact_chat_capability: null 
sourceid: 1629e6890832873d 

林白癡。我問這個問題後幾乎立即就找到了我的問題的答案。

參考:https://stackoverflow.com/a/3591323/2408279

本質上存在用於每個接觸類型的引用I.E.電子郵件,電話等(如果我沒有錯)

+0

我不知道答案,但在未來 – pskink

+0

使用DatabaseUtils.dumpCursor我不知道這是一個事...我覺得愚蠢的現在哈哈。 – jmsGears1

+0

爲什麼愚蠢? Errare humanum est – pskink

回答

0

您應該查詢ContactsContract.CommonDataKinds.Phone,CONTENT_URI表,而讓我知道它是否有幫助。

而作爲pskink說,使用DatabaseUtils.dumpCursor登錄光標..簡單

相關問題