是否有可能从联系簿中过滤掉facebook,whatsapp联系人?

问题描述 投票:0回答:1

我想从android中的电话簿过滤同步的facebook联系人,是否有任何投影内容:// scheme,用于检索内容。

这是我当前查询给定的URI,将光标返回到结果集。

public static Cursor getContactList(ContentResolver cr) {
        // reading all data in descending order according to DATE
        Cursor curContact =  cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
        return curContact;
    }
java android facebook-graph-api android-intent android-contacts
1个回答
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));
}
© www.soinside.com 2019 - 2024. All rights reserved.