本文介绍了如何获得它们用在WhatsApp的或其他应用程序在Android中的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想接触这是用来被其他应用程序(如WhatsApp的或Viber的)请参阅下图
Hi i want to get contact which are used by other application (like whatsapp or viber )please see in below image
请帮我这个问题谢谢
推荐答案
随着 READ_CONTACTS
允许在你的清单,你可以得到同步给出的帐户类型的联系人。对于WhatsApp的是com.whatsapp
。所以:
With the READ_CONTACTS
permission in your manifest, you can get synced contacts given the account type. For WhatsApp it's "com.whatsapp"
. So:
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));
}
这篇关于如何获得它们用在WhatsApp的或其他应用程序在Android中的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!