Android Question jMQTT read retained status

michw

Member
Licensed User
Longtime User
Hello
I have a question, can I use the jMQTT library when I get a message from the server to read ststus of the Retained flag?
The point is to know that the received message is out of date.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can do it by creating your own callback with JavaObject.

Untested code:
B4X:
    Dim client As JavaObject = mqtt
   client = client.GetField("client")
   Dim event As Object = client.CreateEventFromUI("org.eclipse.paho.client.mqttv3.MqttCallback", "callback", Null)
   client.RunMethod("setCallback", Array(event))


Sub Callback_Event (MethodName As String, Args() As Object) As Object
   Log(MethodName)
   Select MethodName
       Case "messageArrived"
           Dim topic As String = Args(0)
           Dim MqttMessage As JavaObject = Args(1)
           
       Case "connectionLost"
           Log("Connection lost")
       Case "deliveryComplete"
           
   End Select
   Return Null
End Sub
MqttMessage API: https://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/MqttMessage.html
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…