我想在我使用smack 4.1.4庫開發的android安卓聊天應用程序中接收聊天消息,我可以發送消息但我不能能夠收到任何消息。下面的方法不會被調用。這裏是我的代碼:什麼時候ProcessPacket在addSyncStanzaListener(smack 4.1.4)中被調用
protected Void doInBackground(String... urls) {
StanzaFilter filter = new StanzaTypeFilter(org.jivesoftware.smack.packet.Message.class);
connection.addSyncStanzaListener(new StanzaListener() {
public void processPacket(Stanza stanza) {
Message message = (Message) stanza;
if (message.getBody() != null) {
String fromName = message.getFrom();
chatMessage newMsg = new chatMessage(message.getBody(), "in");
chatList.add(newMsg);
Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
myadapter = new chatAdapter(actualChatActivity.this, R.layout.single_message, chatList);
chatListView.setAdapter(myadapter);
}
}
}, filter);
return null;
}
public Void setConnection(XMPPConnection connection)
{
this.connection=connection;
if (connection != null) {
// Add a packet listener to get messages sent to us
new ReceiveMessageTask().execute();
}
return null;
}
我怎麼能解決我的問題?
爲什麼要投票。 –
你能告訴我如何使用這個庫發送&接收味精4.1.4。 –