메시지, 이미지, 비디오 등을 보낼 수있는 채팅 응용 프로그램에서 작업 중입니다. 1 : 1 채팅에서이 작업을 그룹 채팅에서도 수행했습니다. 하지만 문제는 다음과 같습니다. - 로그인 할 때마다 항상 각 그룹에 가입해야합니다. 다른 그룹의 메시지를 수신하지 못했습니다.멀티 유저 채팅을위한 메시지를 수신하지 못합니다. Xmpp samck android
여기에 그룹에 가입하는 방법이 있습니다.
MultiUserChat muc= new MultiUserChat(mConnection,"[email protected]");
String userNAme ="222222222";
muc.join(userNAme);
메시지를받지 않을 때마다 그룹에 가입하지 않으면. 그룹에 가입하면 메시지 수신이 시작됩니다.
내 질문은 이것이 유일한 해결책이거나 모든 그룹 채팅이 이런 방식으로 작동한다는 것입니다. 또는 내가 뭔가 잘못하고있다.
나는 봤지만 어떤 해결책도 찾지 못했습니다. 이 중복 질문이나 링크를 감사
이
를 공유하시기 바랍니다 내 질문과 관련된 답변이 경우 코드입니다 : -public boolean createChatRoom() {
String name = edtGroupName.getText().toString();
if (!(connection.isConnected() && name.length() != 0)) {
return false;
}
try {
// Create a MultiUserChat
String userName = Utils.covertIntoSubString(connection.getUser(), Constant.AT);
roomName = (name + md5String(getDateTime()) + userName + Constant.CONFERENCE + connection.getServiceName()).replaceAll(" ", "");
MultiUserChat muc = new MultiUserChat(connection, roomName);
// Create a chat room
muc.create(roomName);
// set Room Name as room subject
muc.changeSubject(name);// RoomName room name
// To obtain the chat room configuration form
Form form = muc.getConfigurationForm();
// Create a new form to submit the original form according to the.
Form submitForm = form.createAnswerForm();
// To submit the form to add a default reply
for (Iterator<FormField> fields = form.getFields(); fields
.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
// Set default values for an answer
submitForm.setDefaultAnswer(field.getVariable());
}
}
// Set the chat room of the new owner
List<String> owners = new ArrayList<String>();
owners.add(connection.getUser());// The user JID
// submitForm.setAnswer("muc#roomconfig_roomowners", owners);
// Set the chat room is a long chat room, soon to be preserved
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
// chat room is public
submitForm.setAnswer("muc#roomconfig_publicroom", true);
// Allows the user to modify the nickname
submitForm.setAnswer("x-muc#roomconfig_canchangenick", true);
// Allows the possessor to invite others
// submitForm.setAnswer("muc#roomconfig_allowinvites", true);
// submitForm.setAnswer("muc#roomconfig_enablelogging", true);
// Only allow registered nickname log
// submitForm.setAnswer("x-muc#roomconfig_reservednick", true);
// Allows the user to register the room
// submitForm.setAnswer("x-muc#roomconfig_registration", true);
muc.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public void inviteFriends(String userJid) {
try {
String groupName = edtGroupName.getText().toString();
Message msg = new Message();
msg.setBody(groupName);
MultiUserChat muc = new MultiUserChat(connection, roomName);
if (muc != null) {
muc.grantMembership(userJid);
muc.invite(msg, userJid, groupName);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void invitationrecvd(){
MultiUserChat chatRoom = new MultiUserChat(con, rum);
try {
chatRoom.join(userName);
saveGroupsToDb(userName + Constant.AT + Constant.HOST + Constant.SLASHSMACK, rum, group);
} catch (Exception e) {
e.printStackTrace();
}
}
그리고이 홈 화면에서 그룹 메시지 리스너입니다
PacketFilter filter = new MessageTypeFilter(Message.Type.groupchat);
groupMessagesListeners = new GroupMessagesListeners();
mConnection.addPacketListener(groupMessagesListeners,filter);
문제는 이미 메시지를 받기 위해 이미 가입 한 그룹에 가입해야한다는 것입니다 ... Elsewise 나는 그룹 회원들과 메시지를 교환 할 수 없었습니다 ... –
가입 후 그룹을 탈퇴합니까? 10 초마다 존재감을 보냄으로써 여전히 방의 일부분이 될 수도 있습니다. – manishg
아니요 그룹을 떠나지 않습니다. 그룹의 일부이지만 donot 메시지를 수신합니다 ... 무엇이 잘못 되었습니까 ... –