asmack中如何接收离线消息

1)smack中登陆:Establishing a Connection

// Create a connection to the jabber.org server.

Connection conn1 = new XMPPConnection("jabber.org");

conn1.connect();



// Create a connection to the jabber.org server on a specific port.

ConnectionConfiguration config = new ConnectionConfiguration("jabber.org", 5222);

Connection conn2 = new XMPPConnection(config);

conn2.connect();

2)smack中消息的处理见:Messaging using Chats

// Assume we've created a Connection name "connection".
ChatManager chatmanager = connection.getChatManager();
Chat newChat = chatmanager.createChat("[email protected]", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});

try {
newChat.sendMessage("Howdy!");
}
catch (XMPPException e) {
System.out.println("Error Delivering block");
}

 

3 asmack android offline message的处理

从这里可以找到答案,Getting offline messages in android chat appplication with use of asmack library

 
  
PacketFilter filter =newMessageTypeFilter(Message.Type.chat);
this.connection.addPacketListener(newPacketListener(){
publicvoid processPacket(Packet packet){

Message message =(Message) packet;
if(message.getBody()!=null){
String fromName =StringUtils.parseBareAddress(message
.getFrom());
Log.i("XMPPClient","Got text ["+ message.getBody()
+"] from ["+ fromName +"]");
if(fromName.equalsIgnoreCase(matchUserJabberId
+"server name")){


// }
}
}
}
}, filter);
 
  


你可能感兴趣的:(smack)