2011-11-15 51 views
0

我想使用我的应用程序更改我的gtalk的状态。为此,我使用了smack API和XMPPClient。但是我在设置连接时遇到了异常。这里是我的代码:尝试使用XMPPClient设置GTalk的状态时出现异常

try 
    { 
     ConnectionConfiguration conn = new ConnectionConfiguration("talk.google.com",Integer.parseInt("5222"),"gmail.com"); 
     Log.d("Debug", "configuration object has been created"); 
     conn.setSASLAuthenticationEnabled(true); 
     conn.setDebuggerEnabled(true); 
     m_xmppConnection = new XMPPConnection(conn); 
     m_xmppConnection.connect(); 
     Log.d("Debug", "try to connect using XMPPConnection"); 
     m_xmppConnection.login("yyy", "xxx"); 
     Presence presence = new Presence(Presence.Type.available); 
     presence.setStatus("Setting the status Programmatically"); 
     presence.setPriority(24); 
     presence.setMode(Presence.Mode.available); 
     m_xmppConnection.sendPacket(presence); 

    } 

    catch(XMPPException e) 
    { 
     e.printStackTrace(); 
    } 

我使用Android 2.2并添加了smack 3.2.1 jar文件。它给服务器没有回应。

这是logcat中的错误。

 11-15 18:40:28.301: W/System.err(7865): Connection failed. No response from server.: 
11-15 18:40:28.311: W/System.err(7865):  at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:120) 
11-15 18:40:28.311: W/System.err(7865):  at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:606) 
11-15 18:40:28.320: W/System.err(7865):  at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:565) 
11-15 18:40:28.320: W/System.err(7865):  at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:991) 
11-15 18:40:28.320: W/System.err(7865):  at com.innominds.ui.Notification.setStatusGtalk(Notification.java:519) 
11-15 18:40:28.320: W/System.err(7865):  at com.innominds.ui.Notification.onClick(Notification.java:238) 
11-15 18:40:28.320: W/System.err(7865):  at android.view.View.performClick(View.java:2408) 
11-15 18:40:28.320: W/System.err(7865):  at android.view.View$PerformClick.run(View.java:8816) 
11-15 18:40:28.320: W/System.err(7865):  at android.os.Handler.handleCallback(Handler.java:587) 
11-15 18:40:28.343: W/System.err(7865):  at android.os.Handler.dispatchMessage(Handler.java:92) 
11-15 18:40:28.343: W/System.err(7865):  at android.os.Looper.loop(Looper.java:123) 
11-15 18:40:28.343: W/System.err(7865):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-15 18:40:28.343: W/System.err(7865):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-15 18:40:28.343: W/System.err(7865):  at java.lang.reflect.Method.invoke(Method.java:521) 
11-15 18:40:28.343: W/System.err(7865):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-15 18:40:28.351: W/System.err(7865):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
11-15 18:40:28.351: W/System.err(7865):  at dalvik.system.NativeStart.main(Native Method) 

为什么我得到这个任何人都可以告诉或帮助?

+1

设置存在或状态

尝试尝试你能添加你的日志吗? – Maggie

+0

我添加了logcat错误。请检查。 –

回答

0

我看到的清晰的执行方式就像是,您正在进行登录,并且很快在您设置状态和状态之后,这是无效的。所以它肯定会给你错误。你需要等待,直到登录过程已经完成之后,你可以用“www.gmail.com”或“https://www.gmail.com”

+0

实际上它不是创建ConnectionConfiguration对象。在第一行我收到异常。 –

+0

你可以检查这个链接:http://www.adarshr.com/papers/xmpp2#references –

+0

我认为对于android你需要给端口号也配置是5222 –

相关问题