我正在尝试让 aSmack 在我的项目中工作。在eclipse中创建了一个标准项目,添加了jar来构建路径/库。开始使用 XMPP 类,但我不确定是否应该做其他事情来正确设置项目(稍后),因为它不起作用。在 aService
中,我开始AsnycTask
连接到 google talk 并发送一条聊天消息。
conn1 = new XMPPConnection(config);
// connecting to the server
try {
conn1.connect();
Log.v(LOG_TAG, "XMPP connected");
} catch (XMPPException xe) {
msg = "XMPPException during connect(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
}
// login
try {
conn1.login(USERNAME, PASSWORD, RESOURCE);
msg = "login ok";
Log.v(LOG_TAG, msg);
} catch (XMPPException xe) {
msg = "XMPPException login(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
StackTraceElement[] st = xe.getStackTrace();
for (int i = 0; i<st.length; i++) {
msg = xe.getStackTrace()[i].toString();
Log.v(LOG_TAG, msg);
}
}
// creating a chat and sending messages
try {
ChatManager chatmanager = conn1.getChatManager();
msg = "creating chat";
Log.v(LOG_TAG, msg);
Chat chat = chatmanager.createChat(BUDDY_ADDRESS, new MessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
String msg = "incoming chat: " + message;
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG);
Log.v(LOG_TAG, msg);
}
});
chat.sendMessage("ahoj");
} catch (XMPPException xe) {
msg = "XMPPException during connect(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
}
(请忽略我愚蠢的异常处理,我还在学习它:-) connect() 方法应该可以工作,因为它不会抛出异常,在 Logcat howewer 中,在“XMPP connected”消息之前,有一个错误,然后是 login() 方法抛出的异常:
03-01 15:13:19.970: WARN/System.err(4465): stream:error (text)
03-01 15:13:19.970: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:261)
03-01 15:13:19.970: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
03-01 15:13:19.975: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)
03-01 15:13:24.640: DEBUG/dalvikvm(3089): GC_EXPLICIT freed 610 objects / 39760 bytes in 216ms
03-01 15:13:26.370: DEBUG/NetworkLocationProvider(2020): onDataConnectionStateChanged 3
03-01 15:13:26.380: DEBUG/MobileDataStateTracker(2020): replacing old mInterfaceName (pdp0) with pdp0 for hipri
03-01 15:13:26.395: DEBUG/MobileDataStateTracker(2020): replacing old mInterfaceName (pdp0) with pdp0 for supl
03-01 15:13:26.400: DEBUG/MobileDataStateTracker(2020): default Received state= CONNECTED, old= CONNECTED, reason= (unspecified), apnTypeList= default,supl
03-01 15:13:31.570: DEBUG/dalvikvm(2806): GC_EXPLICIT freed 173 objects / 10752 bytes in 207ms
03-01 15:13:34.550: VERBOSE/Smacktest_01(4465): XMPP connected
03-01 15:13:36.600: DEBUG/dalvikvm(2583): GC_EXPLICIT freed 1551 objects / 87688 bytes in 236ms
03-01 15:13:39.580: VERBOSE/Smacktest_01(4465): XMPPException login(): No response from the server.
03-01 15:13:39.585: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
03-01 15:13:39.605: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:369)
03-01 15:13:39.605: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:230)
03-01 15:13:39.620: VERBOSE/Smacktest_01(4465): com.biroalex.smacktest_01.SmackTest_01Service$AsyncXMPPConn.doInBackground(SmackTest_01Service.java:105)
03-01 15:13:39.620: VERBOSE/Smacktest_01(4465): com.biroalex.smacktest_01.SmackTest_01Service$AsyncXMPPConn.doInBackground(SmackTest_01Service.java:1)
03-01 15:13:39.635: VERBOSE/Smacktest_01(4465): android.os.AsyncTask$2.call(AsyncTask.java:185)
03-01 15:13:39.640: VERBOSE/Smacktest_01(4465): java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-01 15:13:39.655: VERBOSE/Smacktest_01(4465): java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-01 15:13:39.655: VERBOSE/Smacktest_01(4465): java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-01 15:13:39.660: VERBOSE/Smacktest_01(4465): java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-01 15:13:39.665: VERBOSE/Smacktest_01(4465): java.lang.Thread.run(Thread.java:1096)
03-01 15:13:39.705: VERBOSE/Smacktest_01(4465): creating chat
所以问题是:) 如果我做错了什么,或者项目没有为 aSmack 库在 android 上成为用户做好适当的准备?
有 aSmack 作者的 github https://github.com/rtreffer/asmack,他在其中提到了构建环境,这对我来说完全是中文的。我要创建一个新的构建环境吗?我怎么做?
感谢您的耐心等待!