B4J Question Sending an SMS

raphipps2002

Active Member
Licensed User
Longtime User
With vb.net I have written a program that sends SMS messages via CLICKATELL. They actually provided the script. With my credentials I can access their network. Is there a solution to this using B4J. Their website does provide some info about using JAVA but I dont understand it. Here is the link

https://www.clickatell.com/apis-scripts/scripts/java/

or

for Oracle

https://www.clickatell.com/apis-scripts/scripts/oracle/

Can anyone provide some code to do the same?

B4X:
Imports System.Net
Imports System.IO
Dim client As WebClient = New WebClient
' Add a user agent header in case the requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
client.QueryString.Add("user", "xxxx")
client.QueryString.Add("password", "xxxx")
client.QueryString.Add("api_id", "xxxx")
client.QueryString.Add("to", "xxxx")
client.QueryString.Add("text", "This is an example message")
Dim baseurl As String = "http://api.clickatell.com/http/sendmsg"
Dim data As Stream = client.OpenRead(baseurl)
Dim reader As StreamReader = New StreamReader(data)
Dim s As String = reader.ReadToEnd()
data.Close()
reader.Close()
Return

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   'MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   Dim j As HttpJob
   j.Initialize("sms", Me)
   j.Download2("http://api.clickatell.com/http/sendmsg", _
     Array As String("user", "xxx", _
       "password", "xxx", _
       "api_id", "xx", _
       "to", "xxx", _
       "text", "xxx"))
End Sub

Sub JobDone(Job As HttpJob)
   Log("Success: " & Job.Success)
   If Job.Success Then
     Log(Job.GetString)
   End If
   Job.Release
End Sub

If you are creating a non-UI app then you need to call StartMessageLoop after j.Download2.
 
Upvote 0

maleche

Active Member
Licensed User
Longtime User
I have added the .jar file to my B4J library but It did not show up as "HttpJob". Does this work with B4J?
Is there another Library I can used to send sms via "send to:"?
Thanks
 
Upvote 0
Top