【问题标题】:How to get contacts which are used in whatsapp or other application in android如何获取在whatsapp或android中其他应用程序中使用的联系人
【发布时间】:2014-08-08 05:15:30
【问题描述】:

您好,我想获取其他应用程序(如 whatsapp 或 viber)使用的联系人 请看下图

请帮我解决这个问题 谢谢

【问题讨论】:

  • 嗨,如何找到前手机号码,如 1234567890 及其在whats 应用程序中使用的,那么如何在我的应用程序联系人列表中找到它在whatsapp 中使用的?
  • 有什么尝试?您尝试使用的代码是否存在问题?
  • 现在仍然没有搜索任何代码,如果您有任何解决方案,请告诉我该怎么做?
  • 使用此链接stackoverflow.com/a/35453979/4395114 获取完整描述和android 联系人数据存储表的流程

标签: android contacts whatsapp viber


【解决方案1】:

通过清单中的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));
}

【讨论】:

  • @matiash 它正在返回联系人姓名,数字呢?
  • @CodeGuru 您可以使用此查询返回的联系人 id 查询 Data 表。联系人的所有信息都应该在那里。
  • @VijayRajput 我如何获得whatsapp 联系电话?我只知道名字。
【解决方案2】:

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))); 

    }

【讨论】:

【解决方案3】:

System.out.print("姓名 : "+cursor.getString(contactNameColumn) +"\n "+" 电话号码" + cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 2017-09-07
    • 2015-01-08
    • 2014-01-03
    相关资源
    最近更新 更多