paho.mqtt.android
paho.mqtt.android copied to clipboard
subscribe have no call back when the message arrived when i use this method "public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)"
I use
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
I found a problem
why
public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException {
IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topicFilters);
String activityToken = storeToken(token);
mqttService.subscribe(clientHandle, topicFilters, qos, null, activityToken, messageListeners);
return null;
}
this function return null In the source code in "package org.eclipse.paho.android.service;"-“MqttAndroidClient”; It will lead to the calling function will fail for example
mqttAndroidClient.subscribe(subscriptionTopic, qoss, new IMqttMessageListener[]{new IMqttMessageListener() {
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
System.out.println("arrived:");
}
}});
it will not call the "messageArrived" method when the message arrived from server
while the below method will call normally
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
try {
System.out.println("MQTT:message:"+message.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
Console Log output (if available):
implementation 'androidx.legacy:legacy-support-v4:1.0.0' // Required, for Android version 4.x
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
Same problem: MqttAndroidClient, line 1144
public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException {
IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topicFilters);
String activityToken = storeToken(token);
mqttService.subscribe(clientHandle, topicFilters, qos, null, activityToken, messageListeners);
return null;
}