0
votes

How can I log into my server using anonymous user with ASMACK library for XMPP in android?

I am using OpenFire server

Right now I am getting my self logged in using this code:

String host = "web.xyz.com"; //getText(R.id.host);
String port = "5222";  //getText(R.id.port);
String service = "web.xyz.com";//getText(R.id.service);
String username = Register.username; //getText(R.id.userid);
String password = Register.pass; //getText(R.id.password);

ServiceProvider.Register_Providers(ProviderManager.getInstance());
// Create a connection
connConfig = new ConnectionConfiguration(host, Integer.parseInt(port),service);
connection = new XMPPConnection("host");

try {
    connection.connect();
    Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
} catch (XMPPException ex) {
    ex.printStackTrace();
    Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + ex.getMessage());
    Register.setConnection(null);
}
try {
    connection.login(username, password);
    Log.i("XMPPClient", "Logged in as " + connection.getUser());

    // Set the status to available
    Presence presence = new Presence(Presence.Type.available);
    connection.sendPacket(presence);
    Register.setConnection(connection);
} catch (XMPPException ex) {
    Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
    Register.setConnection(null);
}

Any help will be appreciated

1
what do you use ? openfire ? ejabberd ?cesztoszule
Have you configured local server and configure user credential? server like ejjaberd ,quickblox etc.Tarun - Systematix
yes i am using openfire server. and i can log in with a user name and password that has already been registered in the server. but i cannot log in anonymouslyHassaan Rabbani
see, xmpp/openfire provide us this facility to log in anonymously with the server. i want to log in my self anonymouslyHassaan Rabbani

1 Answers

1
votes

If you want to login anonymously, you must enable anonymous connections at the server, and you does not need to provide username and password, just use connection.loginAnonymously() instead of login()