Dans mon application, je veux créer des groupes et ajouter des utilisateurs aux groupes utilisant smack 4.1. Je suis capable de créer un groupe mais je ne peux pas ajouter d'utilisateur dans ce groupe. Mon code pour créer des groupes est ...Comment créer un chat de groupe xmpp et ajouter des membres en utilisant smack 4.1 dans android
créer un groupe
if (connection != null) {
String groupName = XmppUtils.buildMUCName(grpName);
MultiUserChat multiUserChat = managerMuc.getMultiUserChat(groupName);
if (!multiUserChat.isJoined()) {
boolean createNow;
try {
multiUserChat.createOrJoin(grpName);
createNow = true;
if (createNow) {
Form form = multiUserChat.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", grpName); // form.setAnswer("muc#roomconfig_roomowners", userDate.getUserId().toString() + "@" + Config.ChatValues.SERVICE_NAME);
form.setAnswer("muc#roomconfig_persistentroom", true);
List<String> cast_values = new ArrayList<String>();
cast_values.add("moderator");
cast_values.add("participant");
cast_values.add("visitor");
form.setAnswer("muc#roomconfig_presencebroadcast", cast_values);
multiUserChat.sendConfigurationForm(form);
multiUserChat.join(userDate.getUserId().toString() + "@" + Config.ChatValues.SERVICE_NAME); // multiUserChat.sendConfigurationForm(new Form(DataForm.Type.submit)); //this is to create the room immediately after join.
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
Log.e("createGroup", "=======multiUserChat.isJoined()=====>");
}
}
Code pour ajouter des utilisateurs c'est ce que je fais pour ajouter des utilisateurs
// Create a MultiUserChat using an XMPPConnection for a room
String roomName = groupName + "@" + Config.ChatValues.GROUP_SERVICE_NAME;
MultiUserChat muc2 = managerMuc.getMultiUserChat(roomName);
// User2 joins the new room
// The room service will decide the amount of history to send
// The number of chat room services will decide to accept the historical record
/* DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(0);*/
//history.setSince(new Date());
try {
for (int i = 0; i < selectedLisrArray.size(); i++) {
String userId = selectedLisrArray.get(i).userId.toString() + "@" + Config.ChatValues.SERVICE_NAME;
Log.e("joinGroups", "=========>" + roomName + " users to join " + userId);
muc2.invite(msg, userId, "let's join this room ");
muc2.sendMessage(userId + " : You have joined the group : " + roomName);
}
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
salut ce que vous avez étudié et essayé tant pour pour chat en groupe? – Saveen
Je suis capable de créer un groupe mais je ne peux pas ajouter d'utilisateur dans ce groupe –
puis poster ton code que tu as essayé, comment les autres peuvent-ils comprendre quel est ton problème et pourquoi tu ne peux pas ajouter un utilisateur au chat? –