The SDK simply describes the draft document.

Source: Internet
Author: User

SDK initialization:

HIGHAPI is the SDK core class, and the client holds its unique singleton call to the API.
Highapi constructor function
Final String appId, Apiinitlistener Apiinitlistener)
Parameter description:
AppContext Full Application Context object, it is recommended to use application
The AppID platform is a unique indicator assigned by reference and can be viewed in the background management.
Apiinitlistener initialization listener, because the current SDK is asynchronous initialization, some other settings need to be executed after the completion of the SDK initialization, it can be written in this listener object callback function.

Login for Chat server:
Highapi method
 Public void initchatclient (string account, String pw)

Method Description:

According to the user in my Hi-platform account code to initialize the chat client and verify the identity of the current users, the customer is not registered , the automatic registration . Execute this method after the initial success of the HIGHAPI.

Highapi method

 Public void Addmessagelistener (MessageListener messagelistener)

Method Description:

Adds a listener to the chat service, and the onmessagearrived (hmessage hmessage) method of the listener is recalled when a new message is received. Note: Remove the listener when you do not need to listen.

To remove a chat message listener:

Highapi method

 Public void Removemessagelistener (MessageListener messagelistener)

Method Description:

Removes a registered message listener when it is not called to listen and respond to a new message.

To subscribe to a chat room method:

Highapi method

 Public void chatclientsubscribe (String clientId)

Method Description:

It needs to be called after the chat client is initialized.

Parameter description:

ClientId The client user is the identifier.

To add a subscription listener method:

Highapi method

 Public void Addsubscribelistener (Chatsubscribelistener chatsubscribelistener)

Method Description:

Add a subscription listener for the Chat service to invoke the corresponding callback method when the subscription success/subscription failed/unsubscribe succeeds.

Send Message method:

Highapi method

 Public void sendMessage (String msg, string topic)

Method Description:

Sends a message to the specified channel.

Parameter description:

MSG in custom Format messages

Topic the target channel to be sent

Highapi method

 Public void sendMessage (hmessage hmessage, String topic)

The parameters say:

Hmessage pre-defined message objects

Topic the target channel to be sent

Use the sample demo code:

 Packagecom.yaoshi.wohai.highsdkdemo.activity;Importandroid.app.Application;ImportAndroid.util.Log;ImportCom.wohai.yaoshi.highsdk.chat.listener.ChatSubscribeListener;ImportCom.wohai.yaoshi.highsdk.chat.message.HMessage;ImportCom.wohai.yaoshi.highsdk.chat.service.MessageListener;Importcom.wohai.yaoshi.highsdk.chat.service.exception.NotInitException;ImportCom.wohai.yaoshi.highsdk.main.ApiInitListener;ImportCom.wohai.yaoshi.highsdk.main.HighApi; Public classDemoApplicationextendsApplicationImplementsApiinitlistener {Private StaticHighapi Highapi; Private Final StaticString TAG = "DemoApplication"; @Override Public voidonCreate () {Super. OnCreate (); //Init High SDK.Highapi =NewHighapi ( This, "Testappid", This); } @Override Public voidOnComplete () {Try{highapi.initchatclient ("TestClient", "TESTPW"); Highapi.addmessagelistener (NewMessageListener () {@Override Public voidonmessagearrived (Hmessage hmessage) {log.d (TAG,"Onmessagearrived:message =" +hmessage);            }            }); Highapi.addsubscribelistener (NewChatsubscribelistener () {@Override Public voidonclientsubscribesuccess (String s) {highapi.sendmessage ("Test", "test"); } @Override Public voidOnclientsubscribefail (String S,inti) {} @Override Public voidOnunsubscribefail (String s) {}}); } Catch(notinitexception e) {e.printstacktrace (); }        Try{highapi.chatclientsubscribe ("Test"); } Catch(notinitexception e) {e.printstacktrace (); }    }     Public StaticHighapi Gethighapi () {returnHighapi; }}

The SDK simply describes the draft document.

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.