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

前端 未结 6 1052
终归单人心
终归单人心 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:53

    Only use OfflineMessageManager, if you don't want to get the offline messages automatically (XEP-0013).

    Otherwise just add your StanzaListener to the connection and login.

        XMPPTCPConnectionConfiguration userBasicConfiguration = XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                .setServiceName(SERVICE_NAME)
                .setHost(HOST_NAME)
                .setDebuggerEnabled(false)
                .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                .setPort(PORT)
                .setUsernameAndPassword(userName, password)
                .build();
        AbstractXMPPConnection firstUserConnection = new XMPPTCPConnection(userBasicConfiguration);
        firstUserConnection.connect();
        StanzaFilter filter = new StanzaTypeFilter(Message.class);
        StanzaListener listener = stanza -> {
            System.out.println(stanza.toString());
        };
        firstUserConnection.addSyncStanzaListener(listener,filter);
        firstUserConnection.login();
        while (!Thread.currentThread().isInterrupted()){
    
        }
        firstUserConnection.disconnect();
    

提交回复
热议问题