读书人

对于Smack的研究!(二)

发布时间: 2012-09-22 21:54:54 作者: rapoo

对于Smack的研究!(二)【原创】

Message Events 研究!

?

); } public void displayedNotificationRequested( String from, String packetID, MessageEventManager messageEventManager) { super.displayedNotificationRequested(from, packetID, messageEventManager); // Send to the message's sender that the message was displayed messageEventManager.sendDisplayedNotification(from, packetID); } public void composingNotificationRequested( String from, String packetID, MessageEventManager messageEventManager) { super.composingNotificationRequested(from, packetID, messageEventManager); // Send to the message's sender that the message's receiver is composing a reply messageEventManager.sendComposingNotification(from, packetID); } public void offlineNotificationRequested( String from, String packetID, MessageEventManager messageEventManager) { super.offlineNotificationRequested(from, packetID, messageEventManager); // The XMPP server should take care of this request. Do nothing. System.out.println("Offline Notification Requested (" + from + ", " + packetID + ")"); } }); // User1 creates a chat with user2 Chat chat1 = conn1.createChat(user2); // User1 creates a message to send to user2 Message msg = chat1.createMessage(); msg.setSubject("Any subject you want"); msg.setBody("An interesting body comes here..."); // User1 adds to the message all the notifications requests (offline, delivered, displayed, // composing) MessageEventManager.addNotificationsRequests(msg, true, true, true, true); // User1 sends the message that contains the notifications request chat1.sendMessage(msg); Thread.sleep(500); // User2 sends to the message's sender that the message's receiver cancelled composing a reply messageEventManager.sendCancelledNotification(user1, msg.getPacketID());); } public void displayedNotification(String from, String packetID) { System.out.println("The message has been displayed (" + from + ", " + packetID + ")"); } public void composingNotification(String from, String packetID) { System.out.println("The message's receiver is composing a reply (" + from + ", " + packetID + ")"); } public void offlineNotification(String from, String packetID) { System.out.println("The message's receiver is offline (" + from + ", " + packetID + ")"); } public void cancelledNotification(String from, String packetID) { System.out.println("The message's receiver cancelled composing a reply (" + from + ", " + packetID + ")"); } }); // Create a chat with user2 Chat chat1 = conn1.createChat(user2); // Create a message to send Message msg = chat1.createMessage(); msg.setSubject("Any subject you want"); msg.setBody("An interesting body comes here..."); // Add to the message all the notifications requests (offline, delivered, displayed, // composing) MessageEventManager.addNotificationsRequests(msg, true, true, true, true); // Send the message that contains the notifications request chat1.sendMessage(msg);

读书人网 >移动开发

热点推荐