0

I am use Android MQTT Paho client to send messages with QoS 2. How to save messages if network on device disabled and send when network enabled?

mClient = new MqttAndroidClient(this, uri, clientId, new   MqttDefaultFilePersistence());
MqttConnectOptions conOpt = new MqttConnectOptions();

conOpt.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1);
conOpt.setCleanSession(true);
conOpt.setAutomaticReconnect(true);

mClient.setTraceEnabled(true);

mClient.setCallback(this);
mClient.setTraceCallback(this);

IMqttToken connectToken = mClient.connect(conOpt, null, this);

And offline buffering options:

@Override
public void onSuccess(IMqttToken iMqttToken) {
    this.disconnectedBufferOptions = new DisconnectedBufferOptions();
    this.disconnectedBufferOptions.setBufferEnabled(true);

    mClient.setBufferOpts(disconnectedBufferOptions);

    subscribe(topic);
}

Messages published to topic if the network is available, but if it disabled and enabled again offline messages not sending.

DimParf
  • 285
  • 2
  • 13

0 Answers0