Android Code Snippet Whatsapp Send Function

I hope this help someone:
whatsapp send:
Sub whatsappSend(mobile as string,msg as string)
    Dim sendIntent As Intent
    sendIntent.Initialize(sendIntent.ACTION_MAIN,"")
    sendIntent.PutExtra("jid",mobile & "@s.whatsapp.net")
    sendIntent.Action=sendIntent.ACTION_SEND
    sendIntent.SetPackage("com.whatsapp")
    sendIntent.SetType("text/plain")
    sendIntent.PutExtra("android.intent.extra.TEXT",msg)
    StartActivity(sendIntent)   
End Sub
 

HAH

Well-Known Member
Licensed User
Also this for sending whatsapp image with text:
send whatsapp image:
Sub whatsappSendImage(mobile As String,msg As String)
    Dim FileName As String = "b4a.png"  'change it
    File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName) 'change it
    Dim sendIntent As Intent
    sendIntent.Initialize(sendIntent.ACTION_MAIN,"")
    sendIntent.PutExtra("jid",mobile & "@s.whatsapp.net")
    sendIntent.Action=sendIntent.ACTION_SEND
    sendIntent.SetPackage("com.whatsapp")
    sendIntent.SetComponent("com.whatsapp/.ContactPicker")
    sendIntent.SetType("image/png")
    sendIntent.PutExtra("android.intent.extra.TEXT",msg)
    sendIntent.PutExtra("android.intent.extra.STREAM",Starter.Provider.GetFileUri(FileName))
    StartActivity(sendIntent)
End Sub
Note it depend on fileprovider class, also check mainfest editor ..
Example attached.
 

Attachments

  • sendwhatsappimagewithtext.zip
    20.5 KB · Views: 334

Sabotto

Active Member
Licensed User
The 'mobile' variable must contain the mobile number of the contact, right?
I tried, but I have to manually select the contact to send text and image to.
Also I don't understand what is meant by
B4X:
'Don't miss the code in the manifest editor!!!
 
Top