To register in XMPP server first of all you need to connect with XMPP server.
For register new user in XMPP server AccountManager class is used
To get account manager below code snippet is used
For register new user in XMPP server below method is used.
For this example below is the code for xml file.
Use below activity for the register new user to XMPP server.
Hope this post may helpful for you....
For register new user in XMPP server AccountManager class is used
To get account manager below code snippet is used
AccountManager accountManager = connection.getAccountManager();
For register new user in XMPP server below method is used.
createAccount("USERNAME", "PASSWORD")
For this example below is the code for xml file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/btn_Register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button1" android:layout_below="@+id/button1" android:layout_centerInParent="true" android:layout_marginTop="38dp" android:text="Register" /> </RelativeLayout>
Use below activity for the register new user to XMPP server.
public class DemoActivity extends Activity{ private Button btn_Register; XMPPConnection connection ; ConnectionConfiguration config; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo_activity); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build(); StrictMode.setThreadPolicy(policy); new ConnectToXmpp().execute(); btn_Register = (Button) findViewById(R.id.btn_Register); btn_Register.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { AccountManager accountManager = connection.getAccountManager(); accountManager.createAccount("USERNAME", "PASSWORD"); } catch (XMPPException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } private class ConnectToXmpp extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { config = new ConnectionConfiguration("YOUR SERVER IP", PORT); connection = new XMPPConnection(config); try { connection.connect(); connection.login("ADMIN LOGIN", "ADMIN PASSWORD"); } catch (XMPPException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { } } }
Hope this post may helpful for you....
No comments:
Post a Comment