Android Question Detect whatsapp contacts number.

GalleJ

Member
Hi! First of all I huge hug from Argentina to all community of this forum. Sorry for my english.
I'm newbie programming with B4A but I love it.
I'm developing an app and have to know which is the Whatsapp number for a selected contact on phone.

First, I fill an autocompletetextbox with all contacts in phone. Then, user select a contact, and I use the following Sub to fill a customlistview (CLV1) with all releated phones for that user (work / home/ mobile, etc).

Sub AutoCompleteTextBox_ItemClick (Value As String)
For Each c As cuContact In cu.FindAllContacts(True)
If c.DisplayName = Value Then
For Each phone As cuPhone In cu.GetPhones(c.Id)
CLVSugerirContacto.AddTextItem(phone.Number & " (" & phone.PhoneType & ")",phone.Number)
Next
Exit
End If
Next
End Sub

All works great but the problem is that neither of all showed phones number are in Whatsapp format like +country/city/phone_number and when I try to use that phone to send a whatsapp message using "Intent1.Initialize(Intent1.ACTION_VIEW, "https://api.whatsapp.com/send?phone="&number_in_whatsapp_format&"&text=message here") an error message is displayed saying that the number is not a Whatsapp contact.

For example, if I have a contact number saved as "0291-123456" (without country code), on my phone appears the whatsapp logo and says "Send message to +54-291-123456". So that means whatsapp modify the format of the number but only for its own use. Is there a way to know whatsapp contacts number, or I have to format wrong numbers by code?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Try this, add this code to ContactsUtils:
B4X:
Public Sub FindAllContactsWithWhatsapp As List
    Return FindContactsIdFromData("vnd.android.cursor.item/vnd.com.whatsapp.profile", "data1", "null", "<>", True, False)
End Sub
Does it return anything?
 
Upvote 0

GalleJ

Member
As you suggest me, I changed this:
B4X:
 For Each c As cuContact In cu.FindAllContacts(True)
with this:
B4X:
 For Each c As cuContact In cu.FindAllContactsWithWhatsapp
adding that new Public Sub to ContactsUtils code, but it doesn't return any phone, in any contact.
Any other suggestion?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0
Top