本文介绍了无法获得 jabberId 的 LastActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过这段代码获取特定 jabberId 的上次离线时间.

I am trying to get last offline time of a particular jabberId by this piece of code.

LastActivityManager lActivityManager = LastActivityManager.getInstanceFor(MessageService.getConnection());
        lActivityManager.isLastActivitySupported(to + "@localhost");

        Log.v(TAG, "Last Activity: " + lActivityManager.getLastActivity(to + "@localhost"));
        LastActivity activity = lActivityManager.getLastActivity(to + "@localhost");

但我不断收到服务不可用异常.我已经检查了服务器配置,但此功能从服务器端正确实现.

But I am keep getting service-unavailable exception. I have checked the server configuration but this feature is implemented correctly from server side.

推荐答案

您是否添加了其他 jabber id 作为您的花名册.如果没有尝试添加它们然后检查.如果您使用的是 ejabbered,那么您可以从他们的管理面板手动添加名册进行测试.我使用此代码片段添加名册--

Have you added other jabber id as your roster. If not try adding them then check.If you are using ejabbered then you can manually add roster from their admin panel for testing.I used this code snippet to add roster--

Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);

                    String number = datacollection.get(i).getNo().replace("+", "");
                    String jid = number + "@localhost";

                    Collection<RosterEntry> entries = roster.getEntries();
                    for (RosterEntry entry : entries)
                    {
                        System.out.println(entry);
                        if (entry.getUser().equals(jid))
                        {
                            rosterAlreadyAdded = true;
                            if (entry.getType() != RosterPacket.ItemType.both)
                            {
                                // Create a presence subscription packet and send.
                                Presence presencePacket = new Presence(Presence.Type.subscribe);
                                presencePacket.setTo(jid);
                                connection.sendStanza(presencePacket);
                            }

                        }

                    }
                    if (!rosterAlreadyAdded)
                        roster.createEntry(jid, jid, null);

这篇关于无法获得 jabberId 的 LastActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:29