Something about Android group chat.

Source: Internet
Author: User

When it comes to group chat, a lot of people immediately think of it. Group chat is where I send a message in the group chat interface, and everyone in the group gets it. However, this process we think carefully, and then step by step dissection.

Step one: Starting with group creation, what does it take to create a group? The host and the inviter come together to assemble into a group.

Second step: After the group is created, we have to perform various operations on the group. Referring to the operation, different people on the group operation is different, it is obvious that the group owner's permissions are greater. So what are the rights of different people?

Take a simple example: Group master (1. Group owners can invite friends to join their own groups. Instead, the group owner can remove some people 2. The group master can modify some basic information of the group, such as the group name, some permissions to the specified person, etc. 3. Can delete or exit the group, etc.)

This is a simple analysis of the group. Mainly recently in the group chat this piece, is laborious, the workload is great, tired feel no love! Just do the message processing this piece:

such as message sending and receiving, direct code:

Btn_chat_send = (Button) View.findviewbyid (r.id.chat_send); Btn_chat_send.setonclicklistener (New Onclicklistener () {

@Override public void OnClick (View v) {

Switch (state) {case Msg_do_changetobutton:

if (Et_chat_editmessage.gettext (). Length () > 0) {

chatmsg = new Chatallmessage ();

Chatmsg.setcontent (Et_chat_editmessage.gettext (). toString ());

Chatmsg.setdirection (Chatallmessage.message_right);

Chatmsg.setusername (New String (

MContext.mLoginPersonInfo.Name));

Chatmsg.settime (Urlutils.gettime ());

Chatmsg.setimg (MCONTEXT.MSELECTEDPERSONINFO.ROWID);

byte[] by = Et_chat_editmessage.gettext (). toString (). GetBytes ();

Single chat//

if (type = = 0) {MCONTEXT.M_CLASSSYNC.SENDCHATMSG ((ID-48), by, By.length, 0);

}else if (type==1) {//

MContext.m_ClassSync.SendGroupChatMessage (MContext.mGroupInfoList.get (position) Getrowid (), (ID-48), by, By.length); //

}

List.add (CHATMSG);

Madapter.notifydatasetchanged ();

Chat_listview.setselection (Madapter.getcount ()-1);

Et_chat_editmessage.settext (""); }

Break

Case Msg_do_changetoadd:

Intent intent=new Intent ();

Intent.setclass (Mcontext, Fileactivity.class);

Mcontext.startactivity (Intent); Break

}

}

});

This is the code that receives the section below the main code that the message is sent, which is relatively concise:

Mcontext.sendmessage = new SendMessage () {

@Override public void Send (Chatallmessage msg) {

System.out.println ("direction:" + msg.getdirection ());

Msg.setusername (username);

Msg.setimg (IMG);

List.add (msg);

Mhandler.sendemptymessage (Msg_chat_message_left);

}

};

Chat_listview.setadapter (Madapter);

Chat_listview.setselection (Madapter.getcount ()-1);

Receiving messages is done with an excuse callback.

The effect is mainly that when the message in the EditText input box is empty, the button is the bottom popup button when there is text or other characters in the input box (the length of the input box gets greater than 0 o'clock)

button to the Send button, then click Send Message. The effect is good.

Friends, welcome to actively participate in the study and discussion, Cang babe!

Something about Android group chat.

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.