Getting offline messages in android chat application with use of asmack library

前端 未结 6 1047
终归单人心
终归单人心 2021-02-11 04:12

I am using asmack library for my chat application.I am using below described code for getting messagecount:

ServiceDiscoveryManager manager = ServiceDiscoveryMan         


        
6条回答
  •  [愿得一人]
    2021-02-11 04:50

    GTalkSMS is good example for every basic operation using Asmack lib , below is the small example code i took form GTalkSMS project to get offline messages.

    public static void handleOfflineMessages(XMPPConnection connection, Context ctx)throws Exception {
            OfflineMessageManager offlineMessageManager = new OfflineMessageManager(connection);
    
            if (!offlineMessageManager.supportsFlexibleRetrieval()) {
                Log.d("Offline messages not supported");
                return;
            }
    
            if (offlineMessageManager.getMessageCount() == 0) {
                Log.d("No offline messages found on server");
            } else {
                List msgs = offlineMessageManager.getMessages();
                for (Message msg : msgs) {
                    String fullJid = msg.getFrom();
                    String bareJid = StringUtils.parseBareAddress(fullJid);
                    String messageBody = msg.getBody();
                    if (messageBody != null) {
                        Log.d("Retrieved offline message from " +messageBody);
                    }
                }
                offlineMessageManager.deleteMessages();
            }
        }
    

提交回复
热议问题