Agora Java API Reference for Android

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
io.agora.rtm.RtmClient Class Referenceabstract

## Public Member Functions
abstract void | addEventListener (RtmEventListener listener)
abstract void | removeEventListener (RtmEventListener listener)
abstract void | login (String token, ResultCallback< Void > resultCallback)
abstract void | logout (ResultCallback< Void > resultCallback)
abstract RtmStorage | getStorage ()
abstract RtmLock | getLock ()
abstract RtmPresence | getPresence ()
abstract RtmHistory | getHistory ()
abstract String | getErrorReason (RtmErrorCode errorCode)
abstract void | renewToken (String token, ResultCallback< Void > resultCallback)
abstract void | publish (String channelName, String message, PublishOptions options, ResultCallback< Void > resultCallback)
abstract void | publish (String channelName, byte[] message, PublishOptions options, ResultCallback< Void > resultCallback)
abstract void | subscribe (String channelName, SubscribeOptions options, ResultCallback< Void > resultCallback)
abstract void | unsubscribe (String channelName, ResultCallback< Void > resultCallback)
abstract RtmErrorCode | setParameters (String parameters)
abstract StreamChannel | createStreamChannel (String channelName) throws Exception

## Static Public Member Functions
static synchronized RtmClient | create (RtmConfig config) throws Exception
static synchronized RtmClient | getInstance ()
static synchronized void | release ()
static String | getVersion ()

## Protected Member Functions
abstract RtmErrorCode | initialize (RtmConfig config)
abstract RtmErrorCode | releaseClient ()

## Detailed Description

The RtmClient class.

This class provides the main methods that can be invoked by your app.

RtmClient is the basic interface class of the Agora RTM SDK. Creating an RtmClient object and then calling the methods of this object enables you to use Agora RTM SDK's functionality.

## Member Function Documentation

## ◆ create()

static synchronized RtmClient io.agora.rtm.RtmClient.create | ( | RtmConfig | config | ) | throws Exception
| static

Create rtm client instance.

Returns
  If the method call succeeds, will return
  RtmClient
  instance, if the method call fails, will throw an exception.

Exceptions

  If | error occurs

## ◆ getInstance()

static synchronized RtmClient io.agora.rtm.RtmClient.getInstance | ( |  | ) |
| static

Get rtm client instance.

Returns
  The instance of RtmClient RtmClient.

## ◆ release()

static synchronized void io.agora.rtm.RtmClient.release | ( |  | ) |
| static

Release the rtm client instance.

## ◆ getVersion()

static String io.agora.rtm.RtmClient.getVersion | ( |  | ) |
| static

Get the version info of the Agora RTM SDK.

Returns
  The version info of the Agora RTM SDK.

## ◆ addEventListener()

abstract void io.agora.rtm.RtmClient.addEventListener | ( | RtmEventListener | listener | ) |
| abstract

Adds an event listener for receiving rtm events.

Note: The listener must implement the RtmEventListener interface or use RtmEventListener default implements if do not care about some event.

Parameters

  listener | the RtmEventListener object to be added

## ◆ removeEventListener()

abstract void io.agora.rtm.RtmClient.removeEventListener | ( | RtmEventListener | listener | ) |
| abstract

Remove the specified event listener.

Note: By removing the event listener, the listener will no longer receive notifications from rtm client.

Parameters

  listener | The event specified listener object

## ◆ login()

abstract void io.agora.rtm.RtmClient.login | ( | String | token,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Login the Agora RTM service.

Parameters

  token | Token used to login RTM service.
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ logout()

abstract void io.agora.rtm.RtmClient.logout | ( | ResultCallback< Void > | resultCallback | ) |
| abstract

Logout the Agora RTM service.

Parameters

  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ getStorage()

abstract RtmStorage io.agora.rtm.RtmClient.getStorage | ( |  | ) |
| abstract

Get the storage instance.

Returns
  The instance of RtmStorage

## ◆ getLock()

abstract RtmLock io.agora.rtm.RtmClient.getLock | ( |  | ) |
| abstract

Get the lock instance.

Returns
  The instance of RtmLock

## ◆ getPresence()

abstract RtmPresence io.agora.rtm.RtmClient.getPresence | ( |  | ) |
| abstract

Get the presence instance.

Returns
  The instance of RtmPresence

## ◆ getHistory()

abstract RtmHistory io.agora.rtm.RtmClient.getHistory | ( |  | ) |
| abstract

Get the history instance.

Returns
  The instance of RtmHistory

## ◆ getErrorReason()

abstract String io.agora.rtm.RtmClient.getErrorReason | ( | RtmErrorCode | errorCode | ) |
| abstract

Convert error code to error string.

Parameters

  errorCode | Received error code

Returns
  The error reason

## ◆ renewToken()

abstract void io.agora.rtm.RtmClient.renewToken | ( | String | token,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Renews the token. Once a token is enabled and used, it expires after a certain period of time. You should generate a new token on your server, call this method to renew it.

Parameters

  token | The new token
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ publish() [1/2]

abstract void io.agora.rtm.RtmClient.publish | ( | String | channelName,
|  | String | message,
|  | PublishOptions | options,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Publish a string message in the channel.

Parameters

  channelName | The name of the channel.
  message | The content of the string message.
  options | The options of the message.
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ publish() [2/2]

abstract void io.agora.rtm.RtmClient.publish | ( | String | channelName,
|  | byte[] | message,
|  | PublishOptions | options,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Publish a binary message in the channel.

Parameters

  channelName | The name of the channel.
  message | The content of the string message.
  options | The options of the message.
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ subscribe()

abstract void io.agora.rtm.RtmClient.subscribe | ( | String | channelName,
|  | SubscribeOptions | options,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Subscribe a channel.

Parameters

  channelName | The name of the channel.
  options | The options of subscribe the channel.
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ unsubscribe()

abstract void io.agora.rtm.RtmClient.unsubscribe | ( | String | channelName,
|  | ResultCallback< Void > | resultCallback
| ) |  |
| abstract

Unsubscribe a channel.

Parameters

  channelName | The name of the channel.
  resultCallback | A ResultCallback object. Success: will receives the ResultCallback#onSuccess(Object) callback. Failure: will receives the ResultCallback#onFailure(ErrorInfo) callback.

## ◆ setParameters()

abstract RtmErrorCode io.agora.rtm.RtmClient.setParameters | ( | String | parameters | ) |
| abstract

Set parameters of the sdk or engine

Parameters

  parameters | The parameters in json format

Returns
  RtmErrorCode

## ◆ createStreamChannel()

abstract StreamChannel io.agora.rtm.RtmClient.createStreamChannel | ( | String | channelName | ) | throws Exception
| abstract

Create a stream channel instance.

Parameters

  channelName | The Name of the channel.

Returns
  If the method call succeeds, will return
  StreamChannel
  instance, if the method call fails, will throw an exception.

Exceptions

  If | error occurs