是否可以从通讯录中过滤出facebook,whatsapp联系人?

时间:2019-02-28 13:11:56

标签: java android facebook-graph-api android-intent android-contacts

我想从android中的电话簿中过滤同步的Facebook联系人,是否有任何投射content://方案,以便检索内容。

这是我当前的查询给定URI,在结果集上返回游标。

new LocalDate()

1 个答案:

答案 0 :(得分:1)

是的... 您可以根据帐户类型获得同步的联系人。对于WhatsApp,它是“ com.whatsapp”(* Facebook的帐户类型尚未测试)。所以 只需按照以下示例定义帐户类型

Cursor c = getContentResolver().query(
        RawContacts.CONTENT_URI,
        new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
        RawContacts.ACCOUNT_TYPE + "= ?",
        new String[] { "com.whatsapp","facebook" },
        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));
}
相关问题