1: Registered account 2: Download SDK 3: Import modle Easeui 4: Talk model Add to main project 5: Login function: Code as follows: Emclient.getinstance (). Login (username,password,new Emcallback () {//callback @Override public void onsuccess () {emclient.getinstance (). Groupmanager (). Loadallgroups (); Emclient.getinstance (). Chatmanager (). Loadallconversations (); LOG.D ("main", "Login Chat server successful.) ");
Constact ();
}
@Override public void OnProgress (int progress, String status) {
}
@Override public void OnError (int code, String message) {LOG.D ("main") failed to log on to the chat server. "); } }); 6: When landing successful, jump to contact list: Contact code is as follows: List<string>usernames= emclient.getinstance (). Contactmanager (). Getallcontactsfromserver (); Note: Getting a contact must be performed on a child thread, and the update UI must be performed on the main thread. 7: Jump to the chat page, the code is as follows://new out easechatfragment or instances of its subclasses easechatfragment chatfragment = new Easechatfragment (); Incoming parameter Bundle args = new Bundle (); Args.putint (Easeconstant.extra_chat_type, Easeconstant.chattype_single); Args.putstring (easeconstant.extra_user_id, username); Chatfragment.setarguments (args); Getsupportfragmentmanager (). BeginTransaction (). Add (R.id.container, chatfragment). commit ();
8: Add the friend function, the code is as follows: Emclient.getinstance (). Contactmanager (). Addcontact ("13934127774", "Hello"); Note: The first parameter is the user name to add the friend, and the second argument is the reason for the addition. Add friends must be performed on child threads. 9: Agree to add friend function, the code is as follows: Emclient.getinstance (). Contactmanager (). Acceptinvitation (username); Note: The parameter is the buddy username. Agreeing to add a buddy feature must be performed on a child thread. 10: Reject the friend function, the code is as follows: Emclient.getinstance (). Contactmanager (). Declineinvitation (username); Note: The parameter is a buddy username and the Deny Buddy feature must be performed on a child thread. 11: Monitor the friend dynamic function, the code is as follows: Emclient.getinstance (). Contactmanager (). Setcontactlistener (New Emcontactlistener () {
@Override public void Oncontactagreed (String username) {//Buddy request is agreed
LOG.D ("username", "Friend request is agreed" + username); }
@Override public void oncontactrefused (String username) {//Buddy request denied LOG.D ("username", "Friend request denied" + username);}
@Override public void oncontactinvited (string username, string reason) {//Receive friend Invitation LOG.D ("username", "receive friend Invitation" + username);
Message msg = Mhandler.obtainmessage (); Msg.what = 2; Msg.obj = Username; Handler.sendmessage (msg);
}
Callback this method when @Override public void oncontactdeleted (String username) {//deleted LOG.D ("username", "callback this method when deleted" + username);}
@Override public void oncontactadded (String username) {//Add a contact callback to this method LOG.D ("username", "callback this method by adding a contact" + username);});
12: Instant Get chat message function, code as follows, general download application inside//Chat message public void Chatlistener () {
Emmessagelistener Msglistener = new Emmessagelistener () {
@Override public void onmessagereceived (list<emmessage> messages) {//Receive Message
LOG.D ("Gggggg", messages.tostring ()); }
@Override public void oncmdmessagereceived (list<emmessage> messages) {//Receive a message for a transmission}
@Override public void onmessagereadackreceived (list<emmessage> messages) {//Receive read receipts}
@Override public void onmessagedeliveryackreceived (list<emmessage> message) {//receipt of delivered receipts}
@Override public void onmessagechanged (emmessage messages, Object changes) {//Message state Change}};
Emclient.getinstance (). Chatmanager (). Addmessagelistener (Msglistener); }
Note: When you import a ring letter, you may encounter a conflict between the V4 package and the V7 package, and you need to remove the V4 package. The solution is as follows: Add the Exclude module: ' Support-v4 ' below the V7 package in Build.grade:
Compile (' com.android.support:appcompat-v7:23.4.0 ') {Exclude module: ' Support-v4 '}
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