Openfire+asmack built Android Instant Messenger (iv) 15.4.10

Source: Internet
Author: User

Before the tutorial did not know that you have succeeded,,, no success can ask me Ah =-=

The fourth blog post is to implement the ability to send messages. First, we add such two controls to the layout of the activity after our landing, a edittext and a button to send the data
1  <EditTextAndroid:id= "@+id/edit_text_out"2 Android:layout_width= "0DP"3 Android:layout_height= "Wrap_content"4 Android:layout_weight= "1"5 android:layout_gravity= "Bottom"6 Android:hint= "Say something?" "7             />8  <Button9             Android:id= "@+id/button_send"Ten Android:layout_width= "Wrap_content" One Android:layout_height= "Wrap_content" A Android:scaletype= "Centercrop" - Android:text= "Sent" - android:layout_gravity= "Bottom" the Android:background= "#00000000" -             />

Then go back to the activity and add a listener event for the button and button:

1Button button=(Button) Findviewbyid (r.id.button_send); Find Button2Button.setonclicklistener (NewView.onclicklistener () {3 @Override4              Public voidOnClick (View v) {5EditText input=(EditText) Findviewbyid (r.id.edit_text_out); Find EditText6                 FinalString content=Input.gettext (). toString (); Get the stuff out of there and turn it into a string .7LOG.I (username+ "say = = =", content); Print in the log8                 Try {9Xmppconnection connection =connect.getconnection (); Connecting to the serverTenChatmanager cm =Connection.getchatmanager ();  OneChat chat=cm.createchat ("[Email Protected]/spark 2.6.3",NewMessageListener () {//pass in two parameters one is the speaker: here we put in the name of our server administrator to add IP and version number, the second parameter is the listener of the message A @Override -                          Public voidProcessMessage (chat chat, message msg) {//Set listener for message - msg.setbody (content); MSG (note is in the Asmack bag) put the input we took out theLOG.I (Msg.getfrom () + "said:" +msg.getbody ()); Print Log -                    -                         } -                     }); +Message m =NewMessage (); Send messages to each other - m.setbody (content);  + Chat.sendmessage (M.getbody ()); A}Catch(xmppexception e) { at e.printstacktrace (); -                 } -             } -});

Enter a bunch of things in the formula bar

We can see the server-side printing data, one is sent to hear, one is to receive the hearing of the monitor

We send a data to our virtual machine login user on the client that opens spark:

We are able to receive this message from the client login admin in Spark!

So that we can both send data and receive data! The primary function of the client is basically complete

Tomorrow or afternoon free words will be written next, simple landscaping and trimming, after all, the interface is not so ugly, accept send also rely on print log Ah!

Ask for recommendation =-=!

Openfire+asmack built Android Instant Messenger (iv) 15.4.10

Related Article

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.