0
我是新進MQTT和泛美衛生組織MQTT客戶機庫too.I是能夠成功連接,但是當我訂閱我不能夠得到message.Here是我的代碼如何在Android的MQTT接收報文
String topic = "test123";
int qos = 2;
try {
IMqttToken subToken = client.subscribe(topic, qos);
subToken.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
// The message was published
}
@Override
public void onFailure(IMqttToken asyncActionToken,
Throwable exception) {
// The subscription could not be performed, maybe the user was not
// authorized to subscribe on the specified topic e.g. using wildcards
}
});
} catch (MqttException e) {
e.printStackTrace();
}
你已經發布的代碼只有約申請預訂的,你需要添加回調來處理實際的消息到來。 – hardillb
謝謝@hardillb –
你有解決方案嗎,我正在嘗試同樣的事情,但無法使其工作? –