2014-03-25 67 views
0

如何在Android中使用帶有ASMACK庫的XMPP匿名用戶登錄我的服務器?以匿名用戶身份登錄ASMACK XMPP ANDROID

我使用OpenFire服務器

現在,我讓我的自我登錄使用此代碼:

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); 
} 

任何幫助將不勝感激

+0

你的問題是什麼? – njzk2

+0

你使用什麼?開火 ? ejabberd? – cesztoszule

+0

您是否配置了本地服務器並配置了用戶憑證?服務器像ejjaberd,quickblox等 –

回答