facing problem using smack on android

為{幸葍}努か 提交于 2019-12-10 19:47:57

问题


I have a button in Android Application. When the button is clicked following code is invoked:

TestSmack a = new TestSmack();
a.login("abc@gmai.com","password");

I have a TestSmack class.....in the constructor of this class i wrote

public TestSmack ()
{
    ConnectionConfiguration connConfig = new 
          ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
    connection = new XMPPConnection(connConfig);
}

where XMPPConnection connection is a global variable. And in the login method I try to connect to the Server:

public void login(String userName, String password) throws XMPPException
{
    SASLAuthentication.supportSASLMechanism("PLAIN", 0);
    connection.connect();    
    connection.login(userName, password);
}

But it crashes. I don't know whats happening.

Whereas when I call these all methods from main() and run a simple Java application in separate project (Java, not Android) it works fine.

I am not able to figure out whats the problem.

Thanks


回答1:


Are you using the standard Smack library? When I was playing around with XMPP some months ago, you had to patch the library to make it work on Android. Maybe this helps:

http://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/




回答2:


If anyone is not able to run the programme on android then check if the connect() and login() SMACK API are working fine or not.Because i figured out that u need to add

uses-permission android:name="android.permission.INTERNET" (enclose it within < />seperate braces)

in the AndroidManifest file for connect() and login() to work.And don't forget to use the patched Smack.jar.



来源:https://stackoverflow.com/questions/3750547/facing-problem-using-smack-on-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!