#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim job1 As HttpJob
Dim req As HttpRequest
Dim Button1 As Button
Dim aan As String
Dim url As String
aan = "{""on"": ""true""}"
url = "http://192.168.1.42/api/newdeveloper/lights/2/state"
Dim mLink As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Public Sub PutString(Link As String, Text As String)
PutBytes(Link, Text.GetBytes("UTF8"))
End Sub
Public Sub PutBytes(Link As String, Data() As Byte)
mLink = Link
req.InitializePut2(Link, Data)
CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
Sub Button1_Click
'Send a PUT request to set light state
job1.Initialize("SetLightState", Me)
job1.PutString("http://192.168.1.41/api/newdeveloper/lights/2/state", "{""on"": ""true""}")
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub