如何获取在whatsapp或android中的其他应用程序中使用的联系人
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24276573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get contacts which are used in whatsapp or other application in android
提问by Vijay Rajput
Hi i want to get contact which are used by other application (like whatsapp or viber ) please see in below image
嗨,我想联系其他应用程序(如 whatsapp 或 viber)使用的联系人,请参见下图
please help me about this issue thanks
请帮我解决这个问题谢谢
回答by matiash
With the READ_CONTACTS
permission in your manifest, you can get synced contacts given the account type. For WhatsApp it's "com.whatsapp"
. So:
使用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));
}
回答by Sagar gupta
myWhatsappContacts ArrayList will contain all the phone numbers that are present in your whatsapp Application.
myWhatsappContacts ArrayList 将包含您的 whatsapp 应用程序中存在的所有电话号码。
Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI
,new String[] {ContactsContract.Data._ID
,ContactsContract.Data.DISPLAY_NAME
,ContactsContract.CommonDataKinds.Phone.NUMBER
,ContactsContract.CommonDataKinds.Phone.TYPE}
,ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
+ "' AND " + ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?"
,new String[] { "com.whatsapp" }
, null);
while (cursor.moveToNext())
{
myWhatsappContacts.add(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
}
回答by akash kumar
System.out.print("Name : "+cursor.getString(contactNameColumn) +"\n "+" Phone Number" + cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
System.out.print("姓名:"+cursor.getString(contactNameColumn) +"\n "+" 电话号码" + cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));