Android chat room developed based on XMPP smack openfire (1) [conference service, chat room list, join]

Source: Internet
Author: User

The company has nothing to do. The team lead told me to write a demo and I was so dizzy ....

Let's talk about this chat room first, and let's talk about the server. It's a typical example. It uses the finished openfire. Smack: This is a jar file and library used in javae. To use this package on Android, you need to use the asmack package. This can be found on the official website. In fact, there is no difference between the inside and the smack package. At present, I have not found the specific difference.

Some friends may say what this smack is for. In my personal words, a rack package already packed with XMPP protocol. Provides API operations...

 

1. First, to enter the chat room, you must first know the Conference Service (using spark) where the chat room is located)

/*** Initialize the chat service meeting list */private void inithostroom () {collection 

 

2. Get the jid of the service before you can go to the meeting list:

/*** Initialize the room list */Public void Init () {listdiscoveritems = new arraylist <discoveritems. item> (); // obtain servicediscoverymanagerservicediscoverymanager related to xmppconnection. discomanager = servicediscoverymanager. getinstancefor (constants. conn); // obtain the project of the specified XMPP object // This example obtains the project discoveritems discoitems related to the online Directory Service; try {discoitems = discomanager. discoveritems (jid); // obtain the iterator it = discoitems of the XMPP object to be viewed. getitems (); // displays the project while (it. hasnext () {discoveritems. item = (discoveritems. ITEM) it. next (); system. out. println (item. getentityid (); system. out. println (item. getname (); listdiscoveritems. add (item) ;}} catch (xmppexception e) {e. printstacktrace ();}}

3. Similarly, to enter the meeting room (chat room), you must obtain its ID to enter

 

// The service name must be the service jid = getintent () created in the room (). getstringextra ("jid"); try {muc = new multiuserchat (constants. conn, jid); // create a chat room and enter the room's nick name (nickname) MUC. join ("tests"); log. V (TAG, "Join success");} catch (xmppexception e) {e. printstacktrace ();}

Easy!

 

Well, this article is here, and the next is some internal processing in the chat room.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.