How can i listen incoming subscription request in smack openfire android

孤人 提交于 2019-12-02 12:41:01

A subscription request is not a Message. It is a Presence instead.

So, you probably should try:

StanzaFilter filter = new StanzaTypeFilter(Presence.class);

Reference: RFC 3921 - Section 6 - Managing Subscriptions

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);

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. I am using smack 4.1.9 in my android code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!