Issue #126 - Triggering reconnect when device network state changes. (#135)

* Adding a further fix for android automatic reconnect

Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
This commit is contained in:
James Sutton 2016-10-12 16:04:05 +01:00 committed by GitHub
parent b2c77660cf
commit 3c87e55625

View File

@ -1026,7 +1026,25 @@ class MqttConnection implements MqttCallbackExtended {
return;
}
if (disconnected && !cleanSession) {
if(connectOptions.isAutomaticReconnect()){
//The Automatic reconnect functionality is enabled here
Log.i(TAG, "Requesting Automatic reconnect using New Java AC");
final Bundle resultBundle = new Bundle();
resultBundle.putString(
MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN,
reconnectActivityToken);
resultBundle.putString(
MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null);
resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION,
MqttServiceConstants.CONNECT_ACTION);
try {
myClient.reconnect();
} catch (MqttException ex){
Log.e(TAG, "Exception occurred attempting to reconnect: " + ex.getMessage());
setConnectingState(false);
handleException(resultBundle, ex);
}
} else if (disconnected && !cleanSession) {
// use the activityToke the same with action connect
service.traceDebug(TAG,"Do Real Reconnect!");
final Bundle resultBundle = new Bundle();