2016-06-15 4 views
1

私は匿名でopenfireに新しいユーザーを登録したいと思っています。私はSmack 4.1.0とOpenfire 4.0.2を使用しています。私がすでにユーザーを登録してログインして登録しようとすると、それは完全に機能します。しかし、私はログインせずに他のアカウントに登録したいです。Android、Openfire、Smack、XMPP

私はSmack 4.1 Android anonymous registration to Openfireも参照していますが、動作しません。

接続ビルダー:

Configure conf = new Configure(); 
    conf.configure(new ProviderManager()); 

    XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration 
      .builder(); 
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); 
    config.setServiceName(serverAddress); 
    config.setHost(serverAddress); 
    config.setPort(5222); 
    config.setResource(context.getResources().getString(R.string.resource_name)); 
    config.setDebuggerEnabled(true); 
    config.setSendPresence(true); 
    XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true); 
    XMPPTCPConnection.setUseStreamManagementDefault(true); 
    mConnection = new XMPPTCPConnection(config.build()); 
    XMPPConnectionListener connectionListener = new XMPPConnectionListener(type); 
    mConnection.addConnectionListener(connectionListener); 

ユーザー登録:

public void createNewAccount() { 
    AccountManager accountManager =AccountManager.getInstance(mConnection); 
    if (accountManager != null) { 
     Log.d("Account manager", "NOT NULL"); 
     accountManager.sensitiveOperationOverInsecureConnection(true); 
     Map<String, String> attr = new HashMap<String, String>(); 
     attr.put("username", loginUser); 
     attr.put("password", passwordUser); 
     attr.put("email", loginUser); 
     try { 
      accountManager.createAccount(loginUser, passwordUser, attr); 
      accountCreated = true; 
     } catch (SmackException.NoResponseException e) { 
      e.printStackTrace(); 
     } catch (XMPPException.XMPPErrorException e) { 
      e.printStackTrace(); 
     } catch (NotConnectedException e) { 
      e.printStackTrace(); 
     } 
    } else { 
      Log.d("Account manager", "NULL"); 
    } 
} 

と私は不正な要求エラーを得ました。

06-15 15:53:27.332 2026-10349/com.dsquare.dchat I/System.out: 03:53:27 PM SENT (0): <iq to='192.168.0.250' id='IAX28-1' type='set'><query xmlns='jabber:iq:register'><email>dharmesh1</email><password>dharmesh1</passwor d><username>dharmesh1</username></query></iq> 
06-15 15:53:27.364 2026-10350/com.dsquare.dchat I/System.out: 03:53:27 PM RECV (0): <iq type="error" id="IAX28-1" from="192.168.0.250" to="divyang-pc/9f351hyo93"><query xmlns="jabber:iq:register"><email>dharmesh1</email><password>dharmesh1</passwor d><username>dharmesh1</username></query><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 
06-15 15:53:27.440 2026-10348/com.dsquare.dchat W/System.err: org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: bad-request - modify 
06-15 15:53:27.468 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:2 32) 
06-15 15:53:27.496 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:2 13) 
06-15 15:53:27.508 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager. java:272) 
06-15 15:53:27.512 2026-10348/com.dsquare.dchat W/System.err:  at com.dsquare.xmppservices.XMPPConnection$XMPPConnectionListener.connected(XMPPCo nnection.java:989) 
06-15 15:53:27.528 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionConnectedListener(A bstractXMPPConnection.java:1152) 
06-15 15:53:27.532 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection. java:841) 
06-15 15:53:27.544 2026-10348/com.dsquare.dchat W/System.err:  at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.ja va:360) 
06-15 15:53:27.548 2026-10348/com.dsquare.dchat W/System.err:  at com.dsquare.xmppservices.XMPPConnection$2.doInBackground(XMPPConnection.java:25 2) 
06-15 15:53:27.552 2026-10348/com.dsquare.dchat W/System.err:  at com.dsquare.xmppservices.XMPPConnection$2.doInBackground(XMPPConnection.java:23 4) 
06-15 15:53:27.560 2026-10348/com.dsquare.dchat W/System.err:  at android.os.AsyncTask$2.call(AsyncTask.java:287) 
06-15 15:53:27.564 2026-10348/com.dsquare.dchat W/System.err:  at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
06-15 15:53:27.568 2026-10348/com.dsquare.dchat W/System.err:  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
06-15 15:53:27.576 2026-10348/com.dsquare.dchat W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
06-15 15:53:27.580 2026-10348/com.dsquare.dchat W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
06-15 15:53:27.584 2026-10348/com.dsquare.dchat W/System.err:  at  java.lang.Thread.run(Thread.java:841) 
+0

解決策は見つかりましたか? – AndroidStorm

答えて

1

まずあなたがアカウントを登録する権利権限を持っている場合サーバーの設定/登録&ログインに確認する必要があります。

また、あなたが行うことができます。

accountManager.supportsAccountCreation() 

を、このオプションが利用可能であるかどうかを確認します。

送信した属性を確認してください。パスワードを渡して再度ログインする必要はないと思います。以下は

0

は、ログインせずに、コードが正常に登録、コールのログイン方法とした後、新しいユーザー

public boolean registerUser(String mUserName, String mPassword, String mName, String mEmail) { 

    // Now we create the account: 
    Map<String, String> mUserInfo = new HashMap<>(); 
    mUserInfo.put("name", mUserName); 
    mUserInfo.put("first", mName); 
    mUserInfo.put("email", mEmail); 
    AccountManager accountManager = AccountManager.getInstance(RoosterConnection.getConnection()); 
    accountManager.sensitiveOperationOverInsecureConnection(true); 
    try { 
     Localpart username = null; 
     try { 
      username = JidCreate.bareFrom(mUserName+ "@" + Config.mServiceName).getLocalpartOrNull();//    accountManager.sensitiveOperationOverInsecureConnection(false); 

     } catch (XmppStringprepException e) { 
      e.printStackTrace(); 
     } 
     try { 
      accountManager.sensitiveOperationOverInsecureConnection(true); 
      accountManager.createAccount(username, mPassword, mUserInfo); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
     Log.d(TAG, "saveCredentialsAndLogin() called."); 
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
     prefs.edit() 
       .putString("xmpp_jid", mUserName + "@" + Config.mServiceName) 
       .putString("xmpp_password", mPassword) 
       .putBoolean("xmpp_logged_in", true) 
       .apply();//   RoosterConnection connection = new RoosterConnection(SignUpActivity.this); 
     RoosterConnection connection = RoosterConnection.getInstance(); 
     connection.RoosterConnection(SignUpActivity.this); 
     connection.login(mUserName + "@" + Config.mServiceName,mPassword,true); 
     return true; 
    } catch (SmackException.NoResponseException e) { 
     e.printStackTrace(); 
     Toast.makeText(this, "Error : "+e.getMessage(), Toast.LENGTH_SHORT).show();; 
     return false; 
    } catch (XMPPException.XMPPErrorException e) { 
     Toast.makeText(this, "Error : "+e.getMessage(), Toast.LENGTH_SHORT).show();; 
     e.printStackTrace(); 
     return false; 
    } catch (SmackException.NotConnectedException e) { 
     Toast.makeText(this, "Error : "+e.getMessage(), Toast.LENGTH_SHORT).show();; 
     e.printStackTrace(); 
     return false; 
    } 
} 

を作成し、サーバーからのブロードキャストを取得しますです。

mBroadcastReceiver = new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context context, Intent intent) { 

      String action = intent.getAction(); 
      switch (action) { 
       case RoosterConnectionService.UI_AUTHENTICATED: 
        Log.d(TAG, "Got a broadcast to show the main app window"); 
        //Show the main app window 
        // showProgress(false); 
        Intent i2 = new Intent(this, ContactListActivity.class); 
        i2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
        startActivity(i2); 
        finish(); 
        break; 
      } 

     } 
    }; 
    IntentFilter filter = new IntentFilter(RoosterConnectionService.UI_AUTHENTICATED); 
    this.registerReceiver(mBroadcastReceiver, filter); 
関連する問題