@Override public void onItemClick(int position) { joinChatRoom(roomList.get(position).getJid(), mUser.getUser_name(), ""); if (!isError) { Intent intent = new Intent(); intent.setClass(GroupListActivity.this, GroupChatActivity.class); intent.putExtra("GroupName", roomList.get(position).getName()); intent.putExtra("JID", roomList.get(position).getName() + "@conference." + connection.getServiceName()); startActivity(intent); } } });
/** * 加入一个群聊聊天室 * * @param roomName 聊天室名字 * @param nickName 用户在聊天室中的昵称 * @param password 聊天室密码 * @return */ public MultiUserChat joinChatRoom(String roomName, String nickName, String password) { try { if (!iConnection.isConnected()) { Toast.makeText(this, "服务器连接失败,请先连接服务器", Toast.LENGTH_SHORT).show(); return null; } // 使用XMPPConnection创建一个MultiUserChat窗口 MultiUserChat muc = MultiUserChatManager.getInstanceFor(connection). getMultiUserChat(roomName + "@conference." + connection.getServiceName()); // 聊天室服务将会决定要接受的历史记录数量 DiscussionHistory history = new DiscussionHistory(); history.setMaxChars(0); // history.setSince(new Date()); // 用户加入聊天室 muc.join(nickName, password); return muc; } catch (XMPPException | SmackException e) { e.printStackTrace(); Toast.makeText(JoinGroupActivity.this, "加入失败" + e.getMessage(), Toast.LENGTH_LONG).show(); return null; } }
getMultiUserChat(roomName + "@conference." + connection.getServiceName());
String newusername = username + mConnection.getServiceName(); Log.i("service", mConnection.getServiceName()); AccountManager accountManager = AccountManager.getInstance(mConnection); accountManager.createAccount(username, newpassword);
try { muc = MultiUserChatManager.getInstanceFor(connection).getMultiUserChat(roomName + "@conference." + connection.getServiceName());
public void start() { synchronized (this.lifecycleMonitor) { if (this.running) { return; } try { this.connection.connect(); this.connection.addConnectionListener(new LoggingConnectionListener()); this.connection.login(); if (this.subscriptionMode != null) { Roster.getInstanceFor(this.connection).setSubscriptionMode(this.subscriptionMode); } this.running = true; } catch (Exception e) { throw new BeanInitializationException("failed to connect to XMPP service for " + this.connection.getServiceName(), e); } } }