我正在尝试使用Android中的XMPPConnection更改Gtalk状态。但是,当我尝试通过Wi-Fi时,它无法连接。它正在弹出显示应用程序没有响应。我的代码在这里:
ConnectionConfiguration conn = new ConnectionConfiguration("talk.google.com",Integer.parseInt("5222"),"gmail.com");
m_xmppConnection = new XMPPConnection(conn);
conn.setSASLAuthenticationEnabled(false);
conn.setDebuggerEnabled(true);
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
try
{
m_xmppConnection.connect();
}
catch (XMPPException e1)
{
displayAlertDialog(e1.getMessage());
}
try
{
Log.d("Testing", "try to connect using XMPPConnection");
Log.d("Testing", "try to connect using XMPPConnection-----");
if(m_xmppConnection.isConnected())
{
Log.d("Testing", "It is connected with XMPPConnection");
m_xmppConnection.login(strUname, strPwd);
}
Log.d("Testing", "after giving user name and pwd-----");
Presence presence = new Presence(Presence.Type.available);
m_strGtPrevMsg = presence.getStatus();
m_spEditor.putString("prevmsg", m_strGtPrevMsg);
m_spEditor.commit();
presence.setStatus(strStatus);
Log.d("Testing", "status saved");
presence.setPriority(24);
presence.setMode(Presence.Mode.available);
m_xmppConnection.sendPacket(presence);
Log.d("Testing", "packet send");
}
catch(XMPPException e)
{
// e.printStackTrace();
displayAlertDialog(e.getMessage());
}
任何人都可以帮忙。
答案 0 :(得分:1)
我的猜测:你在UI线程上进行连接,对吗?
制作AsnycTask并在那里进行连接和状态更改。