在android上使用smack遇到问题
我在 Android 应用程序中有一个按钮。单击按钮时,将调用以下代码:
TestSmack a = new TestSmack();
a.login("[email protected]","password");
我有一个 TestSmack 类......在该类的构造函数中,我编写了
public TestSmack ()
{
ConnectionConfiguration connConfig = new
ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
}
其中 XMPPConnection 连接是全局变量的位置。在登录方法中,我尝试连接到服务器:
public void login(String userName, String password) throws XMPPException
{
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
connection.connect();
connection.login(userName, password);
}
但它崩溃了。我不知道发生了什么事。
然而,当我从 main()
调用这些所有方法并在单独的项目(Java,而不是 Android)中运行一个简单的 Java 应用程序时,它工作得很好。
我不知道出了什么问题。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用标准 Smack 库吗?几个月前,当我使用 XMPP 时,您必须修补该库才能使其在 Android 上运行。也许这有帮助:
http://davanum.wordpress .com/2008/12/29/updated-xmpp-client-for-android/
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/
如果有人无法在android上运行该程序,请检查connect()和login()SMACK API是否正常工作。因为我发现你需要添加
uses-permission android:name =“android.permission” AndroidManifest 文件中的“.INTERNET”(将其括在单独的大括号内),
以便 connect() 和 login() 正常工作。并且不要忘记使用已修补的 Smack.jar。
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.