at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:341)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:204)
at org.jivesoftware.smack.Connection.login(Connection.java:357)
//这是我的代码......
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.muc.DiscussionHistory;
import org.jivesoftware.smackx.muc.MultiUserChat;
import android.content.Context;
import android.util.Log;
import com.quickblox.module.chat.QBChat;
public class GroupChatController {
// ================= QuickBlox ===== Step 8 =================
// Get QuickBlox chat server domain.
// There will be created connection with chat server below.
public static final String CHAT_SERVER = QBChat.getChatServerDomain();
private XMPPConnection connection;
private ConnectionConfiguration config;
private Chat groupChat;
private String chatLogin;
private String password;
private String groupName;
private String passgroupName;
Context context;
private String quickusername;
private ChatManager chatManager;
// private boolean isGroupchat;
MultiUserChat muc;
public GroupChatController(String chatLogin, String password) {
this.chatLogin = chatLogin;
this.password = password;
}
//这里我的群聊开始
public void startChat(final String groupName) {
this.groupName = groupName;
// this.isGroupchat = isGroup;
new Thread(new Runnable() {
@Override
public void run() {
// Chat action 1 -- create connection.
Connection.DEBUG_ENABLED = true;
config = new ConnectionConfiguration(CHAT_SERVER);
connection = new XMPPConnection(config);
try
{
//Here is showing error connections
connection.connect();
connection.login(chatLogin, password);
//boolean supports = MultiUserChat.isServiceEnabled(connection, chatLogin+"@muc.chat.quickblox.com");
// Example 416_sedin@muc.chat.quickblox.com
muc = new MultiUserChat(connection,groupName+"@muc.chat.quickblox.com");
DiscussionHistory history = new DiscussionHistory();
history.setMaxStanzas(3);
muc.join(chatLogin, password, history, SmackConfiguration.getPacketReplyTimeout());
muc.addMessageListener(groupchatManagerListener);
} catch (XMPPException e) {
e.printStackTrace();
}/*catch (Exception e) {
// TODO: handle exception
}*/
}
}).start();
}
//创建一个组
public void createGroupChat(final String groupName,final String qucikusername) {
this.passgroupName = groupName;
this.quickusername=qucikusername;
// this.isGroupchat = isGroup;
new Thread(new Runnable() {
@Override
public void run() {
// Chat action 1 -- create connection.
Connection.DEBUG_ENABLED = true;
config = new ConnectionConfiguration(CHAT_SERVER);
connection = new XMPPConnection(config);
try
{
//SASLAuthentication.supportSASLMechanism("PLAIN", 0);
connection.connect();
connection.login(chatLogin, password);
MultiUserChat muc = new MultiUserChat(connection,"groupid_"+groupName+"@muc.chat.quickblox.com");
// int appid= context.getResources().getInteger(R.integer.QuickBoxid);
// Log.i("TAG QUICKID", "QUICKBOX ID CHECK direct"+appid);
muc.create(qucikusername);
//muc.create(appid+"_"+groupName);
// muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
} catch (XMPPException e) {
e.printStackTrace();
}
}
}).start();
}
//Listner for groupchat
private PacketListener groupchatManagerListener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
if (onMessageReceivedListener != null) {
onMessageReceivedListener.onGroupMessageReceived(packet);
}
}
};
//这里发送群组消息
public void sendGroupMessage(String message) {
try {
if(muc!=null)
{
muc.sendMessage(message);
}
}catch(XMPPException xmppe) {
xmppe.printStackTrace();
}
}
/* public void sendMessage(String message) {
try {onMessageReceivedListener
if (chat != null) {
chat.sendMessage(message);
}
} catch (XMPPException e) {
e.printStackTrace();
}
}*/
/* private MessageListener messageListener = new MessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
// 'from' and 'to' fields contains senders ids, e.g.
// 17792-1028@chat.quickblox.com/mac-167
// 17744-1028@chat.quickblox.com/Smack
String from = message.getFrom().split("@")[0];
String to = message.getTo().split("@")[0];
System.out.println(String.format(">>> Message received (from=%s, to=%s): %s",
from, to, message.getBody()));
if (onMessageReceivedListener != null) {
onMessageReceivedListener.onMessageReceived(message);
}
}
};*/
public static interface OnGroupMessageReceivedListener {
void onGroupMessageReceived(Packet packet);
}
private OnGroupMessageReceivedListener onMessageReceivedListener;
public OnGroupMessageReceivedListener getOnMessageReceivedListener() {
return onMessageReceivedListener;
}
public void setOnMessageReceivedListener(OnGroupMessageReceivedListener onMessageReceivedListener) {
this.onMessageReceivedListener = onMessageReceivedListener;
}
// Callback that performs when device retrieves incoming message.
/* private OnMessageReceivedListener onMessageReceivedListener;
public OnMessageReceivedListener getOnMessageReceivedListener() {
return onMessageReceivedListener;
}
public void setOnMessageReceivedListener(OnMessageReceivedListener onMessageReceivedListener) {
this.onMessageReceivedListener = onMessageReceivedListener;
}*/
}
答案 0 :(得分:0)
成功连接后,检查用户是否已通过身份验证(表示是否记录日志)。 所以使用这个
connection.isAuthenticated();
配置MUC之前...