tags:

views:

77

answers:

2

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

TestSmack a = new TestSmack();
a.login("[email protected]","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

+2  A: 

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/

Ulrich Scheller
ya thanks for the reply.actually when accessing XMPP server through android we need to add the line : <uses-permission android:name="android.permission.INTERNET" /> in android.manifest file for the function Connect and Login to work....I hope it will help others
SPB
+2  A: 

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.

SPB