多用户聊天中的 smack 存在监听器没有被调用。使用 Smack Api 登录,然后添加roster.addRosterListener(mRoasterListener); 但是当聊天室的其他用户的存在发生变化时,无法成功收听。我尝试了以下代码来让存在监听器工作:
connection.login(loginUser, passwordUser);
MultiUserChatManager manager =
MultiUserChatManager.getInstanceFor(connection);
muc = manager.getMultiUserChat(roomID + "@" +context.getString(R.string.group_chat_id));
Log.d("Join User: ", "Already Created");
muc.join(Utilities.getUserPhoneNo(context));
muc.addMessageListener(mGroupMessageListener);
Roster roster = Roster.getInstanceFor(connection);//luna
roster.addRosterListener(mRoasterListener);//roasterListener
Log.d("Joined User Phone: ", " " + Utilities.getUserPhoneNo(context));
和这个类来听存在变化......
public class RoasterListener implements RosterListener{
public RoasterListener(Context context){
}
@Override
public void entriesAdded(Collection<String> collection) {
}
@Override
public void entriesUpdated(Collection<String> collection) {
}
@Override
public void entriesDeleted(Collection<String> collection) {
}
@Override
public void presenceChanged(Presence presence) {
System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
}
}
我尝试了 stackoverflow 提供的许多链接,但未能获得任何成功。请帮忙!