Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
mqtt.Initialize("mqtt", "tcp://localhost:51044", "ttt")
mqtt.Connect
Wait For mqtt_Connected (Success As Boolean)
If Success Then
SubscribeWithActionListener("test", mqtt.QOS_2_EXACTLY_ONCE)
End If
End Sub
Private Sub SubscribeWithActionListener(Topic As String, QOS As Int)
Dim client As JavaObject = mqtt.As(JavaObject).GetField("client")
Dim ActionListener As Object = client.CreateEventFromUI("org.eclipse.paho.client.mqttv3.IMqttActionListener", "ActionListener", Null)
client.RunMethod("subscribe", Array(Topic, QOS, Null, ActionListener))
Wait For ActionListener_Event (MethodName As String, Args() As Object)
Log(MethodName & ": " & Args.As(List))
If MethodName = "onSuccess" Then
Dim token As JavaObject = Args(0)
Dim grantedQos() As Int = token.RunMethod("getGrantedQos", Null)
Log(grantedQos(0))
End If
End Sub