2014-06-18 30 views
7

嗨接觸我想這是由其他應用程序使用的接觸(例如WhatsApp和Viber的) 請參閱下面的圖像如何獲得它們在WhatsApp的或其他應用程序使用的Android

enter image description here

請幫我解決這個問題 謝謝

+0

從這裏開始:http://developer.android.com/samples/BasicContactables/index.html – ditkin

+0

喜如何找到前手機號碼,像1234567890及其中使用什麼應用程序,所以如何找到它的使用在我的應用程序聯繫人列表中的whatsapp? –

+0

試過了什麼?您嘗試使用的代碼有問題嗎? – ditkin

回答

24

隨着清單中的READ_CONTACTS權限,您可以獲得同步聯繫人給定的帳戶類型。對於WhatsApp它是"com.whatsapp"。所以:

Cursor c = getContentResolver().query(
     RawContacts.CONTENT_URI, 
     new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY }, 
     RawContacts.ACCOUNT_TYPE + "= ?", 
     new String[] { "com.whatsapp" }, 
     null); 

ArrayList<String> myWhatsappContacts = new ArrayList<String>(); 
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY); 
while (c.moveToNext()) 
{ 
    // You can also read RawContacts.CONTACT_ID to read the 
    // ContactsContract.Contacts table or any of the other related ones. 
    myWhatsappContacts.add(c.getString(contactNameColumn)); 
} 
+0

@matiash它正在返回聯繫人姓名,那麼數字呢? – CodeGuru

+0

@CodeGuru您可以使用此查詢返回的聯繫人ID來查詢數據表。聯繫人的所有信息應該在那裏。 – matiash

+0

@VijayRajput我如何獲得WhatsApp的聯繫電話號碼?我只得到名字。 –

相關問題