I have a button in Android Application. When the button is clicked following code is invoked:
TestSmack a = n开发者_如何学Pythonew 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
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/
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.
精彩评论