Android Question Open WhatsApp?!!

Beja

Expert
Licensed User
Longtime User
Hi all,
Trying to invoke whatsapp but it didn't work, anyone has an idea why?
This is the code that I used. the B4A sub was generated by AI

Open WhatsApp from B4A app:
Sub OpenWhatsApp
    Try
        Dim i As Intent
        i.Initialize(i.ACTION_VIEW, "https://api.whatsapp.com")
        i.SetPackage("com.whatsapp")
        StartActivity(i)
    Catch
        ToastMessageShow("WhatsApp not Installed", True)
    End Try
  
End Sub

Edit:
The required action is to open the WhatsApp App on the phnone, not the WhatsApp website URL
 

Sagenut

Expert
Licensed User
Longtime User
B4X:
Dim in As Intent
Dim pm As PackageManager
in = pm.GetApplicationIntent("com.whatsapp")
StartActivity (in)

You also need to add this in the Manifest
B4X:
AddManifestText(
<queries>
    <package android:name="com.whatsapp"/>
</queries>
)
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
if you want only open whatsapp the source code above is perfect, but if you want also open a chat on a number and send a message:
B4X:
    Dim i As Intent
    in.Initialize(in.ACTION_VIEW, $"whatsapp://send?phone=${Cell}&text=${Testo}"$)
    StartActivity(in)
where Cell is phone number (without "+") and Testo is the message "URLencoded UTF8"
 
Last edited:
Upvote 0
Top