ReconnectionManager in asmack

后端 未结 4 471
野的像风
野的像风 2021-01-03 06:17

I have a project on Android, which needs to use asmack library to enable real time chat.

The key feature is reconnecting mechanism, that means my application can rec

相关标签:
4条回答
  • 2021-01-03 06:23

    Use the latest smack api - I am using 4.1.0

    Then set up re-connection like below:

    ReconnectionManager manager = ReconnectionManager.getInstanceFor(connection);
    manager.enableAutomaticReconnection();
    

    It will automatically re-connect as described Here

    0 讨论(0)
  • 2021-01-03 06:28

    Asmack is supporting Re-connection properly, only problem is that You are using SASL Connection so this is giving problem for because you are trying same connection again on turn Wi-Fi off.Try with set SASL false

    connConfig.setSASLAuthenticationEnabled(false);
    

    required other wise disconnect manually

    connection.disconnect();
    
    0 讨论(0)
  • 2021-01-03 06:34

    Don't use reconnection mechanism which is implemented in ASMACK.

    Use:

        connConfig.setReconnectionAllowed(false);
    

    Instead, you should create BroadcastReceiver which listens to ConnectivityManager.CONNECTIVITY_ACTION. When connection to WIFI or other network is occurred, then you will receive the callback onReceive in your BroadcastReceiver.

    0 讨论(0)
  • 2021-01-03 06:39

    When setting up everything at the start, call

    ReconnectionManager.setEnabledPerDefault(true);
    

    Then connections created from then on will automatically reconnect.

    0 讨论(0)
提交回复
热议问题