Operfire+asmack built Android Instant Messenger (iii) 15.4.9

Source: Internet
Author: User

(can use words to ask to praise =-=, I express bad words to tell me OH)

The last time we got the server-side group data and user information, this can be used for our future use of the friend system to lay the foundation!

But how can we be satisfied with these things alone? One of our instant messaging software is the most important thing is to be able to communicate! So our next step is to accept data from others.
1  Public Static voidFindman () {2System.out.println ("--------Find start----------");3ROSTER roster = Connect.con.getRoster ();//roster represents the list of all friends of a user and the list of users who are applying for a friend4collection<rostergroup> Entriesgroup = roster.getgroups ();//Get group Information5System.out.println ("Team:" +entriesgroup.size ()); 6               for(Rostergroup group:entriesgroup) {7collection<rosterentry> entries =group.getentries ();8System.out.println ("--------groupName--------" + "\ n" +group.getname ());//Cycle Print group names and names9                   for(Rosterentry entry:entries) {TenSystem.out.println ("Name:" +entry.getname ()); One                  } A             } -System.out.println ("--------Find End--------"); -Chatmanager Chatmanager = Connect.con.getChatManager ();
Chatmanager.addchatlistener (New Mychatmanagerlistener ());

Notice that we added two lines to the Findman () function inside the last tool class, the function of which is to register a message listener and set it to listening state. But this mychatmanagerlistener () we haven't written yet!

1 Static classMychatmanagerlistenerImplementsChatmanagerlistener {2          Public voidchatcreated (chat chat,Booleanarg1) {3Chat.addmessagelistener (NewMessageListener () {4 @Override5                  Public voidProcessMessage (chat chat, Message msg) {6Android.os.Message m=handler.obtainmessage ();7m.obj=msg;8 m.sendtotarget ();//fed into handle9                 }Ten             }); One         } A}

We rewrote the Mychatmanagerlistener () implementation of a Chatmanagelistener () interface, which writes a chat-created function to add listening, Create a new message (this message is from the system) put the received MSG (this message is not the system's own) into the incoming handle to do some display operations.

1    Private StaticHandler Handler =NewHandler () {2          Public voidhandlemessage (android.os.Message m) {3Message msg=NewMessage ();4msg=(Message) m.obj;5String[] Message=Newstring[]{Msg.getfrom (), Msg.getbody ()};6System.out.println ("========== received message from:===========" +message[0].tostring ());7System.out.println ("========== received message say:===========" + message[1].tostring ());8         }9};

When a message is sent to the handle, a message is created that is not the system itself. Put it in a new string array, put the first one into the header (the incoming user name), the second one into the body (the user information sent) and print it out in the log.

We first use the server to try, OpenFire has a server to send messages to the function, we send "clam clam" good!

So we can see this server broadcast in the server!

OpenFire's official website can also find such a software, also to download the installation, for testing is very helpful, there is actually our development is in the implementation of a spark of the Android version just

We're testing it with this.

The effect is out, we can not only receive the server broadcast, but also accept the other

User to send us the data!

Write here today, here we realize how to receive other people send data, in the next article we want to implement how to send data, this is our real-time communication function of the preliminary implementation, good looking forward to ah!

(can use words to ask to praise =-=, I express bad words to tell me OH)

Operfire+asmack built Android Instant Messenger (iii) 15.4.9

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.