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

前端 未结 6 1043
终归单人心
终归单人心 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 05:01

    After Googling and searching in documentation,All i got that offlinemanager for getting offline messages.

    But However it is not working in asmack or may be in smack.It always return 0 message.

    Finally by seeing logs i found that each tie when i login i got lot of response from chat server which also contains offline message but with message tag not offline message tag.So I found finally

    You can get offline messages from it by directly setting packet listener after just login .As i below described packet listener you have to implement after login method.

            PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
            this.connection.addPacketListener(new PacketListener() {
                public void 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);
    

    Hope it will help many to find a work around for offline message early as i invested more time to get it out.

提交回复
热议问题