【问题标题】:How can I get my whatsapp number?我怎样才能得到我的whatsapp号码?
【发布时间】:2016-12-23 20:45:13
【问题描述】:

我正在为 Android 开发一个应用程序,并想读取客户端设备中配置的 whatsapp 电话号码。

尝试了以下代码:

AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();

for (Account ac : accounts) {
    String acname = ac.name;
    String actype = ac.type;
    // Take your time to look at all available accounts
    System.out.println("Accounts : " + acname + ", " + actype);
}

if(actype.equals("com.whatsapp")){
    String phoneNumber = ac.name;
}

我也设置了这个权限:<uses-permission android:name="android.permission.GET_ACCOUNTS" />

但 phoneNumber 只返回“Whatsapp”

我需要用户的 whatsapp 电话号码作为我数据库中的记录。我怎样才能得到这个电话号码?

【问题讨论】:

  • 你找到解决办法了吗?

标签: android whatsapp


【解决方案1】:

按照以下步骤操作:

  1. 您需要该联系人的 WhatsApp 的 rawcontact id。
  2. 使用mimetype = "vnd.android.cursor.item/vnd.com.whatsapp.profile"rawcontact id 查询ContactsContract.Data 表。
  3. DATA3 列是 WhatsApp 的编号。

【讨论】:

    【解决方案2】:

    WhatsApp 已经更新了他们的流程,他们不再使用电话号码作为帐户名称来创建帐户,这是此代码所依赖的技巧。

    我认为现在没有任何方法可以从 WhatsApp 应用程序之外获取 WhatsApp 电话号码。

    【讨论】:

      猜你喜欢
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 2023-01-30
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      相关资源
      最近更新 更多