iOS Question is there any way to open whatsapp with especific number?

omarruben

Active Member
Licensed User
Longtime User
Is it possible to open Whatsapp with a especific number, I don't want to send or share anything.
I just want to click on a button on my app and open Whatsapp ready to send a message or click on call

I am achieving this in B4A with
B4X:
Dim i As Intent
    i.Initialize("android.intent.action.SENDTO", "smsto:" & numphone)
    Dim jo As JavaObject = i
    jo.RunMethod("setPackage", Array("com.whatsapp"))
    StartActivity(i)

looking to do the same with B4i
 

omarruben

Active Member
Licensed User
Longtime User
I am trying this code:

B4X:
Dim temp As String = "whatsapp://send?text=Hello%2C%20World!"
 Dim app As Application
 If app.CanOpenUrl(temp) Then app.OpenUrl(temp)
but I have this error:

-canOpenURL: failed for URL: "whatsapp://send?text=Hello%2C%20World!" - error: "This app is not allowed to query for scheme whatsapp"
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
this code works fine, thank you all
and yes !!!! you need #QueriesSchemes : whatsapp
(thank you Semen Matusovskiy and mcqueccu)


and one last thing:

YOU MUST HAVE WHASAPP INSTALLED

B4X:
Sub OpenChatWithNumberW4b(numphone As String)
    Dim temp As String = "whatsapp://send?phone=112312345678&text=hello"
    Dim app As Application
    'Dim su As StringUtils
    'temp = su.EncodeUrl(temp,"UTF8")
    Log(temp)
    If app.CanOpenUrl(temp) Then app.OpenUrl(temp)
End Sub
 
Upvote 0

nedium

Active Member
Licensed User
Longtime User
Could you share an example of a complete project because it gives me an error with

#QueriesSchemes : whatsapp (Unsupported attribute: queriesschemes)

and with

Dim app As Application
(Undeclared variable 'app' is used before any value has been assigned to it.)


I wanted to know if I should add any other configuration
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Could you share an example of a complete project because it gives me an error with

#QueriesSchemes : whatsapp (Unsupported attribute: queriesschemes)

and with

Dim app As Application
(Undeclared variable 'app' is used before any value has been assigned to it.)


I wanted to know if I should add any other configuration
You should start a new thread. Are you using the code in B4i Main module?
 
Upvote 0

Alain75

Member
No need to use javaobject :
Intent setPackage:
    strt.Initialize("android.intent.action.SENDTO","smsto:"&xxxx)
    strt.SetPackage("com.whatsapp")
    StartActivity(strt)
 
Upvote 0
Top