Sunday, 15 September 2013

how to send keepalives in XMPP in Android app

how to send keepalives in XMPP in Android app

i don't know how to implement a keepalive connection in android
http://xmpp.org/extensions/xep-0304.html . I'm using a service with asmack
in my app. After two hours the connection break. I use a reconnection
function to keep alive but doesnt work
public void reconnect(){
try{
connection = Koneksi.getInstance().getConnection();
}catch(NullPointerException e){
SharedPreferences pref =
getSharedPreferences(PREFS_NAME,MODE_PRIVATE);
String username = pref.getString(PREF_USERNAME, null);
String password = pref.getString(PREF_PASSWORD, null);
System.out.println("FDATOS EN MYSERVICE " + username + " " +
username);
try {
Koneksi.getInstance().init();
Koneksi.getInstance().performLogin(username, password);
Koneksi.getInstance().setStatus(true, "");
//
Koneksi.getInstance().getConnection().getRoster().setSubscriptionMode(SubscriptionMode.manual);
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
connection.sendPacket(presence);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

No comments:

Post a Comment