'How to check if mqtt is disconnected after successfully connected in Android Java

I have a Android app that connects to MQTT broker. It successfully connects to the broker. However, when I turned off the mobile data, it still show that the connection is still active.

Is there a way for me to check if the connection is not available?

I used:

mqttClient.isConnected()

To check the connection periodically (every 10 seconds). The result always returns true.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source