"Original" Lightweight instant messaging technology Mobileimsdk:android Client Development Guide

Source: Internet
Author: User

Disclaimer: MOBILEIMSDK currently for personal maintenance of the original open source project, has been compiled some information, hope to the needs of people useful. If you want to communicate with the author, see the article at the bottom of the signature, learn from each other.

MOBILEIMSDK Open Source project code hosting address please enter [email protected]: Click to enter

mobileimsdk android Client SDK documentation: Click to Enter

Learning Communication

    • Discuss the learning and data area: Click here to go to recommended
    • Mobile Instant Messenger communication: 215891622 recommended
    • bug/recommendations sent to:[email protected]

"Write in front."

MOBILEIMSDK's Android Client demo project demonstrates a well-written, easy-to-use Instant Messaging client, with reference to code and best practices, which is located in the SDK full download package Src_all/client/android/ mobileimsdk4a/ directory, this is a complete Eclipse+adt project.

You can also download the pre-built experience of a compiled demo package: Click here to enter.

"First part": Integration preparation> 1th Step: Download the SDK and find the Lib package

① Download Now:
Latest Version Package download this entry, or go to Mobileimsdk's GitHub self-sync code.

② Locate the Lib package:
In the Dist/client/android/ directory of the SDK full download package:

> 2nd Step: Reference Lib Package

Tips: Mobileimsdk's Android client Lib package supports Android 2.3 (included) and above.

① How do I refer to 3rd party jar packages in eclipse?
Copy the Lib package directly to Eclipse's Android project's libs/ directory, F5 refresh.
If it's another Android IDE tool, then so on.

② taking MOBILEIMSDK's demo project as an example, the results are as follows:

"Part Two": Writing code> 1th Step: Basic Configuration
1 //Set Appkey22 Configentity.appkey = "5418023dfd98c579b6001741";3344//set server IP and server ports55 Configentity.serverip = "Rbcore.openmob.net";66 Configentity.serverudpport = 7901;7788//Be sure to initialize the core library first (this is different from iOS and Java side)99 clientcoresdk.getinstance (). Init ( This. context);
> 2nd Step: Callback Settings

① Framework Basic event callback implementation class:

1  Public classChatbaseeventimplImplementschatbaseevent2 {       3     //Login/Drop link result notification4 @Override5      Public voidOnloginmessage (intDwuserid,intDwerrorcode)6     {7         if(Dwerrorcode = = 0)8LOG.I (TAG, "login successful, current assigned user_id=" +Dwuserid);9         ElseTenLOG.I (TAG, "Login failed, error code:" +dwerrorcode); One     } A   -     //Off-line event notification - @Override the      Public voidOnlinkclosemessage (intDwerrorcode) -     { -LOG.I (TAG, "Network connection error has been turned off, error:" +dwerrorcode); -     } +}

② Real-Time message event callback implementation class:

1  Public classChattransdataeventimplImplementschattransdataevent2 {3     //Receive Instant Messaging notifications4 @Override5      Public voidOntransbuffer (String fingerprintofprotocal,intDwuserid, String datacontent)6     {7LOG.I (TAG, "received a message from user" +dwuserid+ ":" +datacontent);8     }9  Ten     //Notification of error messages received from service side feedback One @Override A      Public voidOnerrorresponse (intErrorCode, String errormsg) -     { -LOG.I (TAG, "received server error message, errorcode=" +errorcode+ ", errormsg=" +errormsg); the     } -}

③qos related event callback implementation class:

1  Public classMessageqoseventimplImplementsmessageqosevent2 {3     //message could not complete notification of real-time delivery4 @Override5      Public voidMessageslost (arraylist<protocal>lostmessages)6     {7LOG.I (TAG, "received the system's non-real-time delivery event notification, currently in common"8+lostmessages.size () + "packet QoS guarantee mechanism ended, determined to" cannot be delivered in real time! " ");9     }Ten   One     //notification that the other party has successfully received the message A @Override -      Public voidmessagesbereceived (String thefingerprint) -     { the         if(Thefingerprint! =NULL) -LOG.I (TAG, "received notification of a message event received, message fingerprint =" +thefingerprint); -     } -}

* Set up event callback notification listener:

1 clientcoresdk.getinstance (). Setchatbaseevent (new  Chatbaseeventimpl ()); 2 clientcoresdk.getinstance (). Setchattransdataevent (new  Chattransdataeventimpl ()); 3 clientcoresdk.getinstance (). Setmessageqosevent (new Messageqoseventimpl ());
> 3rd Step: Login Request
1 NewLocaludpdatasender.sendlogindataasync (user name, password) {2 @Override3     protected voidFireaftersendlogin (intcode)4     {5         if(Code = = 0)6LOG.I (TAG, "Data sent successfully!") ");7         Else8LOG.I (TAG, "Data send failed.") The error code is: "+code+"! ");9     }Ten}.execute ();
> 4th step: Send a message
1 NewLocaludpdatasender.sendcommondataasync ("This is a test message ...", the other's userid,true){2 @Override3     protected voidOnPostExecute (Integer code)4     {5         if(Code = = 0)6LOG.I (TAG, "Data has been successfully issued!") ");7         Else8LOG.I (TAG, "Data send failed.") The error code is: "+code+"! ");9     }Ten}.execute ();

"Part III": Common development issues Appendix 1: Can you make the client more power-saving?

Please call the following API to set it (the framework works in SENSEMODE.MODE_3S mode by default):

1 // MOBILEIMSDK The sensitivity mode setting of the core IM framework 2 Configentity.setsensemode (sensemode.mode_10s);

MOBILEIMSDK pre-defined a variety of modes, detailed API Description: Click here to enter.
Special Note: in order to ensure the consistency of the algorithm, the above settings need to be consistent across all platform clients and the server, otherwise unpredictable problems will occur.

"Original" Lightweight instant messaging technology Mobileimsdk:android Client Development Guide

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.