2013-04-29 64 views
0

我正在通過ContactsContract執行查詢以檢索聯繫人詳細信息(特別是其郵遞地址)。問題的關鍵是,我想跳過那些來自例如WhatsApp,LinkedIn,Skype和其他應用程序同步通訊錄...查詢聯繫人詳細信息跳過其他應用程序的同步聯繫人

我的代碼是:

Uri uri = StructuredPostal.CONTENT_URI; 
String[] sqlSelect = new String[] { StructuredPostal.FORMATTED_ADDRESS, StructuredPostal.DISPLAY_NAME, StructuredPostal.STREET, StructuredPostal.CITY, StructuredPostal.POSTCODE, StructuredPostal.COUNTRY }; 
String sqlWhere = StructuredPostal.MIMETYPE + "=?" + " AND " + 
      "(" + StructuredPostal.STREET + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.CITY + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.POSTCODE + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.COUNTRY + " LIKE '%" + queryString + "%')"; 
String[] sqlWhereParams = new String[]{ StructuredPostal.CONTENT_ITEM_TYPE }; 
String sortOrder = StructuredPostal.STREET + " ASC"; 

Cursor cursor = this.getContentResolver().query(uri, sqlSelect, sqlWhere, sqlWhereParams, sortOrder); 
    if (cursor.moveToFirst()) { 
     do { 
      String formattedAddress = cursor.getString(cursor.getColumnIndex(StructuredPostal.FORMATTED_ADDRESS)); 
      String displayName = cursor.getString(cursor.getColumnIndex(StructuredPostal.DISPLAY_NAME)); 
      String street = cursor.getString(cursor.getColumnIndex(StructuredPostal.STREET)); 
      String city = cursor.getString(cursor.getColumnIndex(StructuredPostal.CITY)); 
      String postcode = cursor.getString(cursor.getColumnIndex(StructuredPostal.POSTCODE)); 
      String country = cursor.getString(cursor.getColumnIndex(StructuredPostal.COUNTRY)); 
      Log.d(TAG, formattedAddress + " " + displayName + " " + street + " " + city + " " + postcode + " " + country); 

     } while (cursor.moveToNext()); 
    } 

LogCat輸出正確打印聯繫人我在地址簿中手動添加:

<postal_address> <contact_full_name> <street> <city> <postcode> <country> 

但正在印製像(LinkedIn)從第三方應用程序導入的聯繫人:

<email> <contact_full_name> <email> null null null 

應在何處(如果郵寄地址是不可用):

null <contact_full_name> null null null null 

是使用不當接觸的第三方應用程序?有什麼方法可以跳過第三方同步的聯繫人嗎?

回答

0

這是可以做到與過濾鏈接的帳戶,我決定只過濾從谷歌未來的那些(ContactsContract.RawContacts.ACCOUNT_TYPE + "= 'com.google'):

String sqlWhere = StructuredPostal.MIMETYPE + "=?" + " AND " + ContactsContract.RawContacts.ACCOUNT_TYPE + "= 'com.google' AND " + 
      "(" + StructuredPostal.STREET + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.CITY + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.POSTCODE + " LIKE '%" + queryString + "%'" + " OR " + 
      StructuredPostal.COUNTRY + " LIKE '%" + queryString + "%')"; 
相關問題