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

嗨,我想获得其他应用程序使用的联系人(如whatsapp或viber)
请看下图

请帮我解决这个问题
谢谢

解决方法

使用清单中的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));
}

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...