Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 登录到xmpp服务器时出错_Android_Xmpp - Fatal编程技术网

Android 登录到xmpp服务器时出错

Android 登录到xmpp服务器时出错,android,xmpp,Android,Xmpp,公共void connect(){ final ProgressDialog dialog=ProgressDialog.show(这是“正在连接…”,请稍候…”,false); 线程t=新线程(新的可运行线程(){ @凌驾 公开募捐{ //创建连接 ConnectionConfiguration ConnconConfig=新连接配置( 主机、端口、服务); XMPPConnection连接=新的XMPPConnection(connconconfig); 试一试{ connection.co

公共void connect(){

final ProgressDialog dialog=ProgressDialog.show(这是“正在连接…”,请稍候…”,false);
线程t=新线程(新的可运行线程(){
@凌驾
公开募捐{
//创建连接
ConnectionConfiguration ConnconConfig=新连接配置(
主机、端口、服务);
XMPPConnection连接=新的XMPPConnection(connconconfig);
试一试{
connection.connect();
Log.i(“XMPPChatDemoActivity”,
“已连接到”+connection.getHost());
}捕获(XMPPException-ex)
{
Log.e(“XMPPChatDemoActivity”,“无法连接到”
+connection.getHost());
Log.e(“XMPPChatDemoActivity”,例如toString());
设置连接(空);
}
试一试{
//SASLAuthentication.支持SaslMechanism(“平原”,0);
连接。登录(用户名、密码);
Log.i(“XMPPChatDemoActivity”,“以“+connection.getUser()登录”);
//将状态设置为“可用”
状态=新状态(Presence.Type.available);
连接。发送数据包(存在);
设置连接(连接);
花名册=connection.get花名册();
集合条目=花名册.getEntries();
对于(排班条目:条目){
Log.d(“XMPPChatDemoActivity”,
"--------------------------------------");
Log.d(“XMPPChatDemoActivity”、“RosterEntry”+条目);
Log.d(“XMPPChatDemoActivity”,
“用户:”+entry.getUser());
Log.d(“XMPPChatDemoActivity”,
名称:“+entry.getName());
Log.d(“XMPPChatDemoActivity”,
状态:“+entry.getStatus());
Log.d(“XMPPChatDemoActivity”,
类型:“+entry.getType());
Presence entryPresence=花名册.getPresence(条目
.getUser());
Log.d(“XMPPChatDemoActivity”,“状态:”
+getStatus());
Log.d(“XMPPChatDemoActivity”,“状态类型:”+entryPresence.getType());
Presence.Type=entryPresence.getType();
if(type==Presence.type.available)
Log.d(“XMPPChatDemoActivity”、“状态可访问”);
Log.d(“XMPPChatDemoActivity”、“Presence:+entryPresence”);
}
}捕获(XMPPException-ex){
Log.e(“XMPPChatDemoActivity”,“无法以身份登录”
+用户名);
Log.e(“XMPPChatDemoActivity”,例如toString());
设置连接(空);
}
dialog.dismise();
}
});
t、 start();
dialog.show();
}
} 我已经创建了新用户新用户创建成功,但当我使用用户名和密码登录时,它给我错误,登录时给我以下错误。 03-12 07:10:58.495:E/XMPPChatDemoActivity(13411):使用机制摘要进行SASL身份验证失败-MD5:

我正在使用端口:5222

    private XMPPConnection xmppConnection = null;

    private void setConfiguration() {
    ConnectionConfiguration config = new ConnectionConfiguration(IP_address,
            PORT); // ip address of your server and port is 5222
    SmackConfiguration.setPacketReplyTimeout(Config.PACKET_TIME_OUT);
    System.out.println(SmackConfiguration.getVersion());
    config.setRosterLoadedAtLogin(true);
    config.setSendPresence(true);
    config.setSASLAuthenticationEnabled(true);
    // config.setCompressionEnabled(true);
    config.setVerifyChainEnabled(false);
    config.setReconnectionAllowed(true);
    xmppConnection = new XMPPConnection(config);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        config.setTruststoreType("AndroidCAStore");
        config.setTruststorePassword(null);
        config.setTruststorePath(null);
    } else {
        config.setTruststoreType("BKS");
        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                    + File.separator + "security" + File.separator
                    + "cacerts.bks";
        config.setTruststorePath(path);
    }


xmppConnection.connect();
xmppConnection.login(username,password);
}
试试这段代码。你需要禁用SASL身份验证,以防客户端可能不支持它。所以这行代码可以帮你解决这个问题

 cc.setSASLAuthenticationEnabled(false);

希望能有所帮助。

让我知道是否有关于xmpp的任何信息。:)是的,当然还有一件事,我还想在我的应用程序中发送表情符号检查这个OK谢谢..我会尝试这段代码,如果有任何pblm,我会让你知道。
       ConnectionConfiguration cc = new ConnectionConfiguration(domain,
                port, service);
        // SASLAuthentication.supportSASLMechanism("PLAIN", 0);
        cc.setSASLAuthenticationEnabled(false);
        cc.setRosterLoadedAtLogin(true);
        cc.setCompressionEnabled(false);
        cc.setReconnectionAllowed(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            cc.setTruststoreType("AndroidCAStore");
            cc.setTruststorePassword(null);
            cc.setTruststorePath(null);
        } else {
            cc.setTruststoreType("BKS");
            String path = System.getProperty("javax.net.ssl.trustStore");
            if (path == null) {
                path = System.getProperty("java.home") + File.separator
                        + "etc" + File.separator + "security"
                        + File.separator + "cacerts.bks";
            }
            cc.setTruststorePath(path);
        }
   XMPPConnection connection = new XMPPConnection(cc);
   connection.login(username, password);
 cc.setSASLAuthenticationEnabled(false);