java - 是否可以从通讯录中过滤掉 facebook、whatsapp 联系人?
问题描述
我想从android中的电话簿中过滤同步的facebook联系人,是否有任何投影内容://方案,以便检索内容。
这是我当前的查询给定的 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;
}
解决方案
是的...您可以在给定帐户类型的情况下获得同步的联系人。对于 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));
}
推荐阅读
- c# - Automapper - 如何实现查找
- xml - XSLT:在重新排列 XML 时面临多个父节点的问题
- r - R通过grep搜索将数据附加到df列(每个模式=新列)
- publishing - 如何使用 Adobe Animate 制作 Android App Bundle 以将其发布到谷歌商店?
- r - R:一张图中日期对象的两个折线图
- r - 如何从文件名中获取最新日期
- c# - RazorPages 如何将 GET 参数传递给 OnGet?
- node.js - 尝试在 backeng 中比较密码时出错 - NODE.JS
- flutter - ontap时如何从其他小部件打开下拉菜单
- spring-boot - Springboot日志级别禁用Gitlab上的DEBUG日志记录