我试图通过这段代码获取特定 jabberId 的最后离线时间。
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");
但我不断收到服务不可用的异常。 我已检查服务器配置,但此功能已从服务器端正确实现。
最佳答案
您是否添加了其他 jabber ID 作为您的名册。如果没有尝试添加它们然后检查。 如果您使用 ejabbered,那么您可以从管理面板手动添加名册进行测试。 我使用此代码 fragment 添加名册--
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);
关于android - 无法获取 jabberId 的 LastActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31331329/