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

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

    Replace your code with this . I have used this code its running fine.

    public int offlinemessagecount(){
        try {
    
            ServiceDiscoveryManager manager = ServiceDiscoveryManager
                    .getInstanceFor(connection);
            DiscoverInfo info = manager.discoverInfo(null,
                    "http://jabber.org/protocol/offline");
            Form extendedInfo = Form.getFormFrom(info);
            if (extendedInfo != null) {
                String value = extendedInfo.getField("number_of_messages")
                        .getValues().next();
    
                return Integer.parseInt(value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    
    }
    

提交回复
热议问题