How can I get my whatsapp number?

坚强是说给别人听的谎言 提交于 2019-12-08 03:36:55

问题


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

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" />

but phoneNumber only returns "Whatsapp"

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


回答1:


Follow these steps:

  1. You need the rawcontact id of WhatsApp of that contact.
  2. Query ContactsContract.Data table with mimetype = "vnd.android.cursor.item/vnd.com.whatsapp.profile" with that rawcontact id.
  3. The DATA3 column is the number of WhatsApp.



回答2:


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.

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



来源:https://stackoverflow.com/questions/22639640/how-can-i-get-my-whatsapp-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!