Not able to get LastActivity of a jabberId

北慕城南 提交于 2019-12-06 10:16:59

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/31331329/not-able-to-get-lastactivity-of-a-jabberid

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