我如何在smack openfire android中监听传入的订阅请求 [英] How can i listen incoming subscription request in smack openfire android

查看:188
本文介绍了我如何在smack openfire android中监听传入的订阅请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一击开火创建一个android聊天应用程序.我面临的问题是我知道如何发送和接受订阅请求,但是如何知道我是否收到任何订阅请求. 我使用了Stanza侦听器,但该侦听器仅侦听传入的聊天消息,而不侦听订阅请求. 下面是我的代码

I am creating an android chat application using a smack open fire. The problem that I am facing is I know how to send and accept subscription requests but how can I know if I have received any subscription request. I have used Stanza listener but the listener is only listening to incoming chat messages, not subscription requests. Below is my code

StanzaFilter filter=new StanzaTypeFilter(Message.class);
        PacketCollector collector=connection.createPacketCollector(filter);
        connection.addAsyncStanzaListener(new StanzaListener() {
            @Override
            public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
                Log.wtf("MA","Stanz listner");
            }
        },filter);

我是初学者,请帮助我如何收听传入的订阅请求.预先感谢.

I am a beginner in smack, please help me how can I listen for incoming subscription request. Thanks in advance.

推荐答案

这是我在Android代码中所做的事情

This is how I have done in my android code

StanzaFilter subscribefilter = PresenceTypeFilter.SUBSCRIBE;
PresenceSubscribeListener subscribeListener = new PresenceSubscribeListener(context.getApplicationContext(), connection);
connection.addSyncStanzaListener(subscribeListener, subscribefilter);

然后,该连接对象已在Android的长期运行服务中被引用.这样做的目的是,当您的应用程序在后台接收数据包时,您仍然可以处理传入的状态数据包.

And then this connection object has been referenced in a long running service in Android. This has been done such that when a packet is received when you app is in background, you can still process the incoming presence packet.

P.S.我在Android代码中使用了smack 4.1.9.

P.S. I am using smack 4.1.9 in my android code.

这篇关于我如何在smack openfire android中监听传入的订阅请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆