Android Easeui 3.0 Instant Messaging problem Rollup _android

Source: Internet
Author: User

0, about the registered account is needless to say.

1, the creation of applications, access to Appkey

0. Create Application

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 ring letter Instant Messaging function, need to download the SDK


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

3 issues that may occur after the 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 the Easeui contains V4 packets, 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 be an error.

The error message is as follows:

Initially thought to be the reason for the JDK, but after the data was found to be a package conflict problem, the solution:
Solution: Delete the V7 in the project, delete the V4 inside the Easeui, and add the V7 package inside the Easeui. This will not be an error.

4, Environmental information configuration:

4.0: Add permissions to the Androidmanifest.xml file:

4.1: Configure the Ring letter key

4.2 Initialization: Here write the simplest, other functions such as friend validation reference demo

4.3.0 in Easeui use, related to Baidu map, in this need to go to Baidu Map website to create applications, apply for Appkey:
The specific configuration is as follows (here you only need to fill in the Appkey, do not need to initialize):

4.3.1: When you send a picture, you may have the ability to look at the big picture, view the map, and provide the activity in Easeui, we only need to register in our own manifest file. The specific code is as follows:

3. Use

Provides a space for you to skip the login registration feature on the document. In this introductory section there may be holes in the place.

Note: 0, the registration function generally requires the server to achieve; 1, in the use of initialization, EASEUI default has automatic login function, need to pay attention to use, if you need to turn off this feature, in the initialization section, add the following code:

To cancel the automatic login 
Options.setautologin (false);

0, Easeui fit android6.0:

In the download good demo, find Runtimepermissions folder, (specific path to see map), and then add the code in mainactivity (see map)

Add the following code to the Mainactivity

1, in the message listening to need to see if you have to go here, do not use toast to verify, because in the listener is a child thread.

2, the use of the avatar, the user name of this information. It is recommended that the Avatar URL and user nickname exist in the local database. This does not have to go backstage every time (take the background, you may have a flash of the situation), if the user information has changed, you can give a background to send a message, and then to update the data inside the database.

3, on the top of the message and cancel the top, can be implemented by extending the message, in the loop letter, each message can attach an extended message, we can add a property in the extension message, and then set the adapter based on this property to achieve the top, when sending a message to each of the top session of the message, is appended to the extended attribute.

4, the ban on group chat, you can enter to chat when the first judge of their own state of prohibition, and then when the ban and was canceled, let the background to send a message, to solve this problem.

5, on the set of circular head, you need to use a custom view in the layout file to replace the ImageView in the Easeui;

6, custom message list, the last message if the expression, add this sentence, you can put the final expression out.

Holder.messages_text.setText (Easesmileutils.getsmiledtext, Easecommonutils
. Getmessagedigest ( Listemconversation.get (position). Getlastmessage (), context)), Buffertype.spanna
BLE);

Position:

if (Listemconversation.get (position). Getlastmessage (). GetType () = EMMessage.Type.LOCATION) {
Holder.messages_ Text.settext ("[position]");
}

7, oneself send a message to oneself

Delete and a user session, if you need to keep the chat record, preach false\
emclient.getinstance (). Chatmanager ()
. Deleteconversation (username, true); \
//Receive a friend request and then create a session add an extended message
emmessage emmessage = Emmessage
. Createreceivemessage ( EMMessage.Type.CMD);
Emmessage.setfrom (username)//sender
Emmessage.addbody (new Emtextmessagebody ("I request to add you as a friend");//Create Message
Emmessage.setunread (true);/whether read
Emmessage.setchattype (EMMessage.ChatType.Chat);//Chat type
Emmessage.setmsgtime (System.currenttimemillis ());//Message Time
emmessage.setattribute ("MessageType", " Friendinvitation ");//Extended Message
Emmessage.setto (PublicStaticData.prefreences.getString (" Ueserid "," ")); sent to
emclient.getinstance (). Chatmanager (). Savemessage (emmessage); Send yourself a message.

8, custom message entries, if you need to achieve such as QQ chat page sharing, you need to define the layout of such an item, the amount, not, because it is two. One of the received sent.

Then Easeui provides an interface (Easecustomchatrowprovider), and we can implement this interface.
The key code is as follows:

8 first to write the number of custom entries (*2, one received, one sent) in the quantity required

Define message types to receive and send

8.1 To achieve three methods:

Getcustomchatrowtypecount ()
getcustomchatrowtype (emmessage message)
Getcustomchatrow (Emmessage message, Intposition,baseadapter adapter)

Getcustomchatrowtype

In this method, we can use the extended message of the message to realize, we first judge the content of the extended message, and then load 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 it, which provides Easechatrowpic.java code)

Importandroid.content.Context;
importandroid.text.Spannable;
Importandroid.view.View;
Importandroid.widget.BaseAdapter;
Importandroid.widget.ImageView;
Importandroid.widget.TextView;
Importandroid.widget.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);
@Override protected Voidoninflatview () {inflater.inflate () = message.direct () = = EMMessage.Direct.RECEIVE?
R.layout.myease_row_received_picture2:r.layout.myease_row_sent_picture2, this); }
@Override protected 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);
@Override public Voidonsetupview () {//set content String titlestring = "";
String contentstring = "";
String picurlstring = ""; Sets the 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://sent successfully progressbar.setvisibility (View.gone);
Statusview.setvisibility (View.gone);
Break
casefail://Send failure progressbar.setvisibility (view.gone);
Statusview.setvisibility (view.visible);
Break
caseinprogress://sent 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 ();}} 
} @Override protected Voidonupdateview () {adapter.notifydatasetchanged ();} @Override protected Voidonbubbleclick () {} }

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

Use a custom entry

9, chat interface of the start mode using Singletask if there is a repeat of the interface jump, will appear page jump.

10, after the integration of Easeui, found a problem. May appear in some versions of the phone a little desktop icon, the program crashes the situation, the solution is as follows:

Create a armeabi-v7a under Libs, and copy so in the Armeabi in v7a, compatible with more versions of the phone.

11, found in the chat page voice playback function can not be used, did not click the playback effect, looking for a long time reason. Discover the fragment of clicking Avatar before entering chat ... It's a pit, it took half a day.

Messagelist.setitemclicklistener (New Easechatmessagelist.messagelistitemclicklistener () {
@Override
public void Onuseravatarclick (String username) {
System.err.println ("click Avatar");
Avatar Click event
publicstaticdata.thisfriendsid = Long
parselong (username);
System.err.println ("Username:" +long.parselong (username));
Intent Intent = new Intent (xingactivity_01.this,
shejiaofrienddetailsactivity.class);
StartActivity (intent);
}
@Override public
void Onresendclick (final emmessage message) {
//Postback Messages button click event
}
@Override
public void Onbubblelongclick (Emmessage message) {
//Bubble Box long by event
}
@Override Public
Boolean Onbubbleclick (Emmessage message) {
//Bubble box Click event, EASEUI has the default implementation this event, if need to overwrite, return value returns True
//notice here, be sure to return false, Otherwise, the Click event overrides the return
false;
@Override public
void Onuseravatarlongclick (String username) {
//TODO auto-generated method stub
}
});

Click events for Messages

Well, the Easeui part is here to share. If you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.