您可以使用 Android 中的以下侦听器检测 XMPP 连接是否丢失
connection.addConnectionListener(new ConnectionListener() {
@Override
public void reconnectionSuccessful() {
// TODO Auto-generated method stub
System.out.println("ConnectionListener ==== >>>>> reconnectionSuccessful");
}
@Override
public void reconnectionFailed(Exception arg0) {
// TODO Auto-generated method stub
System.out.println("ConnectionListener ==== >>>>> reconnectionFailed >>> " + arg0.toString());
}
@Override
public void reconnectingIn(int arg0) {
// TODO Auto-generated method stub
System.out.println("ConnectionListener ==== >>>>> reconnectingIn >>> " + arg0);
}
@Override
public void connectionClosedOnError(Exception arg0) {
// TODO Auto-generated method stub
System.out.println("ConnectionListener ==== >>>>> connectionClosedOnError >>>" + arg0.toString());
}
@Override
public void connectionClosed() {
// TODO Auto-generated method stub
System.out.println("ConnectionListener ==== >>>>> connectionClosed");
}
});