我正在使用smack-android:4.1.0进行聊天,我正在使用openfire。当我想在android中使用AccountManager创建一个帐户时我得到 jid-malformed 我已经尝试了所有的东西,但我无法找到解决方案,我正在讨厌我的代码来创建一个用户
if(connection != null && connection.isConnected()){
Log.e("=AccountManager= ","AccountManager");
// Registering the user
AccountManager accountManager = AccountManager.getInstance(connection);
//Log.e("=supportsAccountCreation= ","="+accountManager.supportsAccountCreation());
//Log.e("=getAccountInstructions= ","="+accountManager.getAccountInstructions());
Map<String, String> attributes = new HashMap<>();
attributes.put("email", "kanta@signitysolutions.in");
attributes.put("username", "spota421");
if (accountManager!=null&&accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount("spota421", "xxxxx", attributes);
}
}
以下是我在我的控制台中的响应,请任何人指导我,我做错了什么。
D/SMACK: SENT (0): <iq to='52.62.104.135:9090' id='4Clc6-3' type='get'><query xmlns='jabber:iq:register'></query></iq>
10-02 07:40:21.670 7216-7330/
D/SMACK: RECV (0): <iq type="error" id="4Clc6-3" to="ip-172-31-28-121.ap-southeast-2.compute.internal/8xk12y6kvq" from="52.62.104.135:9090"><query xmlns="jabber:iq:register"/><error code="400" type="modify"><jid-malformed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: jid-malformed - modify
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:213)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:332)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at org.jivesoftware.smackx.iqregister.AccountManager.supportsAccountCreation(AccountManager.java:144)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at com.signity.spota.xmpp.CreateConnection.Authenticate(CreateConnection.java:182)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at com.signity.spota.xmpp.CreateConnection.access$200(CreateConnection.java:34)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at com.signity.spota.xmpp.CreateConnection$connect.onPostExecute(CreateConnection.java:121)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at com.signity.spota.xmpp.CreateConnection$connect.onPostExecute(CreateConnection.java:55)
10-02 07:40:21.675 7216-7216/com.signity.spota W/System.err: at android.os.AsyncTask.finish(AsyncTask.java:636)
答案 0 :(得分:0)
尝试这个我希望它的工作。
if (XMPPConnection != null && XMPPConnection.isConnected()) {
Log.e("=AccountManager= ", "AccountManager");
AccountManager accountManager = AccountManager.getInstance(XMPPConnection);
Map<String, String> attributes = new HashMap<>();
try {
if (accountManager != null && accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
Jid jid = JidCreate.entityBareFrom("spot123" + "@" + "yourOpenFireService As String");
accountManager.createAccount(jid.getLocalpartOrNull(), "Spot1234sdfsd", attributes);
}
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XmppStringprepException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
我有点迟了,但你应该逃避你的JID,或者你需要删除/替换JID元字符集。