Android 我怎样才能得到我的whatsapp号码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22639640/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:17:32  来源:igfitidea点击:

How can I get my whatsapp number?

androidwhatsapp

提问by LuisCarrizo

I am developing an app for Android and want to read the whatsapp telephone number configured in the client device.

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

Tried the following code:

尝试了以下代码:

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

I also set this permission: <uses-permission android:name="android.permission.GET_ACCOUNTS" />

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

but phoneNumber only returns "Whatsapp"

但电话号码只返回“Whatsapp”

I need the user's whatsapp phone number as a record in my database. How can I get this phone number?

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

回答by ppyyxx

Follow these steps:

按着这些次序:

  1. You need the rawcontactid of WhatsApp of that contact.
  2. Query ContactsContract.Datatable with mimetype = "vnd.android.cursor.item/vnd.com.whatsapp.profile"with that rawcontactid.
  3. The DATA3column is the number of WhatsApp.
  1. 您需要该rawcontact联系人的 WhatsApp id。
  2. 具有该ID 的查询ContactsContract.Data表。mimetype = "vnd.android.cursor.item/vnd.com.whatsapp.profile"rawcontact
  3. DATA3列是WhatsApp的数量。

回答by zmarties

WhatsApp have updated their process, and they no longer create the account using the phone number as the account name, which is the trick this code relied upon.

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

I do not believe there is any way to now get hold of the WhatsApp phone number from outside the WhatsApp app.

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