Android Easeui 3.0 Instant Messaging The pit I've stepped on.

Source: Internet
Author: User

0, on the registration of accounts, needless to say. 1. Create an app, get Appkey

0. Create an App

1. Fill in the information

2. Get Appkey

2. Integration

0. Create a new project first

1, here mainly introduces the use of Easeui to integrate the Instant messaging function of the ring letter, need to download the SDK


2, the Easeui as a dependency into the project, and then establish a dependency relationship

3 issues that may occur after you import:
3.0

<uses-permission android:name="android.permission.ACCESS_MOCK_LACATTON>

This permission error, after consulting the official technology, the answer is that you can remove the permission. Specific permission information can refer to the permissions in the demo.
3.1 Because Easeui contains V4 package, resulting in V4 packet conflict, but after the deletion of the project V4 package, or error. The reason is that in the project contains V7 package, and V7 package contains V4, so still will error.
The error message is as follows:

Started thinking it was the JDK, but after looking at the data it was a packet conflict problem, the solution:
Solution: The project V7 deleted, and then the easeui inside the V4 deleted, and then add V7 package in the Easeui inside. This will not be an error.

4, Environment information configuration:

4.0: Add permissions to the Androidmanifest.xml file:

4.1: Configure the Ring letter key

4.2 Initialization: Write here the simplest, other functions like friend verification and other reference demo

4.3.0 in Easeui use, involving Baidu map, in this need to self-Baidu map to create applications, apply for Appkey:
The configuration is as follows (just fill in the Appkey and do not need to initialize):

4.3.1: When you send a picture, you may see a larger image, view the function of the map, in Easeui provide these activity, we just need to register in their own manifest file. The specific code is as follows:

3. Use

Skip the login registration feature on the document here. Here are some areas where there may be pits.
Note: 0, the registration function is generally required to implement the server; 1, in the use of initialization, easeui default automatic login function, need to note, if you need to turn off this feature, in the initialization section, add the following code:
To cancel automatic login
Options.setautologin (FALSE);

0, Easeui suitable for android6.0:
In the download good demo, find the Runtimepermissions folder, (the specific path to see the picture), and then add a bit of code in the mainactivity (see image)

1, in the message monitoring if you need to see if you come here, do not use a toast to verify, because in the listener belongs to the child thread.
2, the use of the avatar, user name of this information. It is recommended that the URL of the avatar and the user's nickname exist in the local database, so that you do not have to go back to the background to fetch (take the background to take, may appear a flash of the situation), if the user information has changed, can let the background to send a pass message, and then to update the data inside the database.
3, about the top of the message and the cancellation of the top, can be implemented by extending the message, in the ring, each message can be attached to the extension message, we can add a property in the extension message, and then set the adapter in accordance with this property to implement the top, when the message is sent to each of the pinned session of the message, are appended with the extended property.
4, about the group chat ban, you can enter to chat when the first judge of their own forbidden state, and then when banned and banned words, let the background to send a message, to solve the problem.
5, about setting round head, need to use custom view in layout file to replace ImageView in Easeui;

6, custom message list, the last message if it is an expression, add this sentence, you can put the last expression.

holder.messages_text.setText( EaseSmileUtils.getSmiledText(context, EaseCommonUtils.getMessageDigest(listEMConversation.get(position).getLastMessage(), context)),BufferType.SPANNABLE);

Position:

if (listEMConversation.get(position).getLastMessage().getType() == EMMessage.Type.LOCATION) {            holder.messages_text.setText("[位置]");}

7. Send a message to yourself

Delete and a user session, if you need to keep the chat record, pass Falseemclient. getinstance(). Chatmanager(). Deleteconversation(username, true);\Receive a friend request and then create a session to add an extended message emmessage Emmessage = Emmessage. Createreceivemessage(Emmessage. Type. CMD);Emmessage. Setfrom(username);//SenderEmmessage. Addbody(New Emtextmessagebody ("I asked to add you as a friend"));//Create a messageEmmessage. Setunread(true);//whether ReadEmmessage. Setchattype(Emmessage. Chattype. Chat);//Chat typeEmmessage. Setmsgtime(System. Currenttimemillis());//Message TimeEmmessage. SetAttribute("MessageType","Friendinvitation");//Extended MessageEmmessage. Setto(Publicstaticdata. Prefreences. getString("Ueserid",""));// Send ToEmclient. getinstance(). Chatmanager(). Savemessage(Emmessage); Send a message to yourself

8, custom message entries, if you need to implement like QQ Chat page sharing, you need to define a layout of such items, the amount, not, because it is two. One of the received sends. Then Easeui provides an interface (Easecustomchatrowprovider), we go to implement this interface can be.
The key code is as follows:
8 first go to write the number of custom entries (in the quantity required, one received, one sent)

8.1 To implement three methods:

getCustomChatRowTypeCount()getCustomChatRowType(EMMessage message)getCustomChatRow(EMMessage message, intposition,BaseAdapter adapter)

In this method can be implemented by the extension message of the message, we first determine the content of the extension message, and then to load the different layouts separately.

To create a different entry

The custom entry code is as follows (you can refer to Easeui's own entry style to implement, the Easechatrowpic.java code is provided here)

Importandroid. Content. Context;Importandroid. Text. Spannable;Importandroid. View. View;Importandroid. Widgets. Baseadapter;Importandroid. Widgets. ImageView;Importandroid. Widgets. TextView;Importandroid. Widgets. TextView. Buffertype;Importcom. Hyphenate. Chat. Emclient;Importcom. Hyphenate. Chat. Emmessage;Importcom. Hyphenate. Chat. Emmessage. Chattype;Importcom. Hyphenate. Easeui. R;Importcom. Hyphenate. Easeui. Publicdata. Staticdata;Importcom. Hyphenate. Easeui. Utils. Easesmileutils;Importcom. Hyphenate. Exceptions. Hyphenateexception;Importcom. Lidroid. Xutils. Bitmaputils;Public Classeasechatrowonepicextendseasechatrow {Privatetextviewtitle;PrivateImageViewimg1;Privatetextviewcontent;Publiceasechatrowonepic (Contextcontext,emmessage message, Intposition,baseadapter adapter) {Super (Context,message, Position,adapter);} @Overrideprotected Voidoninflatview () {Inflater. Inflate(Message. Direct() = = Emmessage. Direct. RECEIVE? R. Layout. Myease_row_received_picture2:r. Layout. Myease_row_sent_picture2, this);} @Overrideprotected Voidonfindviewbyid () {title= (TextView) Findviewbyid (R. ID. Myease2_received_title);Content= (TextView) Findviewbyid (R. ID. Myease2_received_content);img1= (ImageView) Findviewbyid (R. ID. Myease2_received_image132);} @Overridepublic Voidonsetupview () {//set content String titlestring ="";String contentstring ="";String picurlstring ="";Set title try{titlestring =message. Getstringattribute("Ext_title");Contentstring =message. Getstringattribute("Ext_detail");Picurlstring =message. Getstringattribute("EXT_IMG1");}catch (Hyphenateexception e) {E. Printstacktrace();} spannable Span;span = Easesmileutils. Getsmiledtext(context,titlestring);Title. SetText(Span,buffertype. Spannable);Set content span = Easesmileutils. Getsmiledtext(context,contentstring);Content. SetText(Span,buffertype. Spannable);if (!picurlstring. Equals("") {//Set picture Bitmaputils bitmaputils =newbitmaputils (GetContext (), Staticdata. Picpath);Bitmaputils. Display(img1,picurlstring);} handletextmessage ();}protected Voidhandletextmessage () {if (message. Direct() = = Emmessage. Direct. SEND) {Setmessagesendcallback ();Switch (message. Status()) {Casecreate:progressbar. Setvisibility(View. GONE);Statusview. Setvisibility(View. VISIBLE);Send Message Break;casesuccess://Send Success ProgressBar. Setvisibility(View. GONE);Statusview. Setvisibility(View. GONE);                   Break;casefail://Send failed ProgressBar. Setvisibility(View. GONE);Statusview. Setvisibility(View. VISIBLE);                   Break;caseinprogress://Send in ProgressBar. Setvisibility(View. VISIBLE);Statusview. Setvisibility(View. GONE);                   Break;Default Break;}}else{if (!message. isacked() &&message. Getchattype() = = Chattype. Chat) {try{emclient. getinstance(). Chatmanager(). Ackmessageread(Message. Getfrom(), Message. Getmsgid());}catch (Hyphenateexception e) {E. Printstacktrace();}}}} @Overrideprotected Voidonupdateview () {Adapter. notifydatasetchanged();} @Overrideprotected Voidonbubbleclick () {}}

Use: In the activity where fragment is located, set the properties of the chat page, the code is as follows:

Use a custom entry

9, Chat screen start mode use Singletask if there is an interface repeat jump, will appear page jump.
10, after the integration of Easeui, found a problem. May appear on some versions of the phone on a little desktop icon, the program crashes, the solution is as follows:
Create a armeabi-v7a under Libs, copy the so in Armeabi in v7a and make it compatible with more versions of your phone.

11, found in the chat page of the voice playback function can not be used, no click on the effect of playing, looking for a long time reason. Discover the properties of the click Avatar before entering the chat fragment ... It was a pit, and it took half a day.

Messagelist.setitemclicklistener (NewEasechatmessagelist.messagelistitemclicklistener () {@Override                     Public void Onuseravatarclick(String username) {System.err.println ("Click on Avatar");//Avatar Click eventPublicstaticdata.thisfriendsid = Long. Parselong (username); System.err.println ("Username:"+long.parselong (username)); Intent Intent =NewIntent (xingactivity_01. This, Shejiaofrienddetailsactivity.class);                    StartActivity (Intent); }@Override                     Public void Onresendclick(FinalEmmessage message) {//Re-send Message button click event}@Override                     Public void Onbubblelongclick(Emmessage message) {//Bubble Box Long press event}@Override                     Public Boolean Onbubbleclick(Emmessage message) {//Bubble box Click event, EASEUI has the default implementation of this event, if required to overwrite, return value is returned true                        //Note here, be sure to return FALSE, otherwise the Click event will overwrite the                        return false; }@Override                     Public void Onuseravatarlongclick(String username) {//TODO auto-generated method stub}                });

Well, the Easeui part is shared here. Hope to help you to solve some of the pits. Thank you.

Wen/Liqingfeng Lin (Jane book author)
Original link: http://www.jianshu.com/p/fa36152f1d57#
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Android Easeui 3.0 Instant Messaging The pit I've stepped on.

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.