如何在android中获取whatsapp或其他应用程序中使用的联系人

Vij*_*put 7 android contacts viber whatsapp

您好我想获得其他应用程序使用的联系人(如whatsapp或viber)请参见下图

在此输入图像描述

请帮我解决这个问题谢谢

mat*_*ash 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));
}
Run Code Online (Sandbox Code Playgroud)