The Agora RTM SDK provides a stable messaging mechanism for you to implement real-time messaging scenarios.

This page lists the core APIs of the Agora RTM SDK. Unless otherwise specified, most of the core APIs should only be called after the login method call succeeds and after you receive the onSuccess callback.

Following are the core functionalities that the Agora RTM SDK.

Login & Logout

Connection states between the SDK and the Agora RTM system is a core concept for you to understand before developing an RTM app. For more information, see Manage Connection States.

Method Description
createInstance Creates and returns an RtmClient instance.
login Logs in the Agora RTM system.
  • Success: The local user receives the onSuccess callback.
  • Failure: The local user receives the onFailure callback. See LoginError for the error codes.
logout Logs out of the Agora RTM system.
  • Success: The local user receives the onSuccess callback.
  • Failure: The local user receives the onFailure callback. See LogoutError for the error codes.
release Releases all resources used by the RtmClient instance.
Event Description
onConnectionStateChanged Occurs when the connection state changes between the SDK and the Agora RTM system.

Sending a peer-to-peer message

Method Description
createMessage Creates and returns an RtmMessage instance.
sendMessageToPeer Sends an (offline) peer-to-peer message to a specified user. See SendMessageOptions for the offline messaging settings.
Event Description
RtmClientListener.onMessageReceived Occurs when receiving a peer-to-peer message.

Querying the online status of the specified users

Method Description
queryPeersOnlineStatus Queries the online status of the specified user(s).

User attribute operations

Method Description
setLocalUserAttributes Substitutes the local user's attributes with new ones.
addOrUpdateLocalUserAttributes Adds or updates the local user's attribute(s).
deleteLocalUserAttributesByKeys Deletes the local user's attributes using attribute keys.
clearLocalUserAttributes Clears all attributes of the local user.
getUserAttributes Gets all attributes of a specified user.
getUserAttributesByKeys Gets the attributes of a specified user using attribute keys.

Channel attribute operations

Method Description
setChannelAttributes Sets the attributes of a specified channel with new ones.
addOrUpdateLocalUserAttributes Adds or updates the attribute(s) of a specified channel.
deleteLocalUserAttributesByKeys Deletes the attributes of a specified channel by attribute keys.
clearLocalUserAttributes Clears all attributes of a specified channel.
getUserAttributes Gets all attributes of a specified channel.
getUserAttributesByKeys Gets the attributes of a specified channel by attribute keys.
Event for all channel members Description
onAttributesUpdated Returns all attributes of the channel when the channel attributes are updated. See setEnableNotificationToChannelMembers for how to enable it.

Retrieving channel member count of specified channel(s)

Method Description
getChannelMemberCount Gets the member count of specified channel(s).

Joining or leaving a channel

Method Description
createChannel Creates an RtmChannel instance.
  • Success: Returns an RtmChannel instance.
  • Failure: Returns null.
join Joins a channel.
leave Leaves a channel.
getId Retrieves the channel ID.
release Releases all resources used by the current channel.
Event Description
onMemberJoined Occurs when a remote user joins the channel.
onMemberLeft Occurs when a remote channel member leaves the channel.
onMemberCountUpdated Occurs when the number of the channel members changes, and returns the new number.

Channel message

Method Description
createMessage Creates and returns an RtmMessage instance.
sendMessage Allows a channel member to send a message to all members in the channel.
Event Description
RtmChannelListener.onMessageReceived Occurs when receiving a channel message.

Retrieving a member list of the channel

Method Description
getMembers Retrieves the member list of a channel.
  • Success: The local user receives the onSuccess callback and the member list of the channel.
  • Failure: The local user receives the onFailure callback. See GetMembersError for the error codes.

Call invitation management

  • API calling sequence for canceling a sent call invitation:
  • API calling sequence for accepting or declining a received call invitation:
Method for Managing a Call Manager Description
getRtmCallManager Gets an Agora RTM call manager.
setEventListener Sets the event listener of an RtmCallManager instance.
Caller Method Description
createLocalInvitation Allows the caller to create and manage a LocalInvitation object.
sendLocalInvitation Allows the caller to send a call invitation to a remote user.
cancelLocalInvitation Allows the caller to cancel a sent call invitation.
acceptRemoteinvitation Allows the callee to accept a received call invitation.
refuseRemoteInvitation Allows the callee to decline a received call invitation.
Callee Method Description
createLocalInvitation Allows the caller to create and manage a LocalInvitation object.
acceptRemoteinvitation Allows the callee to accept a received call invitation.
refuseRemoteInvitation Allows the callee to decline a received call invitation.
Caller Event Description
onLocalInvitationReceivedByPeer Callback to the caller: occurs when the callee receives the call invitation.
onLocalInvitationCanceled Callback to the caller: occurs when the caller cancels a sent call invitation.
onLocalInvitationAccepted Callback to the caller: occurs when the callee accepts the call invitation.
onLocalInvitationRefused Callback to the caller: occurs when the callee declines the call invitation.
onLocalInvitationFailure Callback to the caller: occurs when the life cycle of an outgoing call invitation ends in failure. See LocalInvitationError for the error codes.
Callee Event Description
onRemoteInvitationReceived Callback to the callee: occurs when the callee receives a call invitation. At the same time, the SDK returns a RemoteInvitation object to the callee.
onRemoteInvitationAccepted Callback to the callee: occurs when the callee accepts a received call invitation.
onRemoteInvitationRefused Callback for the callee: occurs when the callee declines a received call invitation.
onRemoteInvitationCanceled Callback to the callee: occurs when the caller cancels the call invitation.
onRemoteInvitationFailure Callback to the callee: occurs when the life cycle of the incoming call invitation ends in failure. See RemoteInvitationError for the error code.

Renew the current RTM Token

Method Description
renewToken Renews the current RTM Token.
Event Description
onTokenExpired Occurs when the current RTM Token exceeds the 24-hour validity period.

Logfile Settings & Version Check

  • Logfile-related operations can be done after creating an RtmClient instance and before calling the login method.
  • getSDKVersion is a static method. You can call it before creating an RtmClient instance.
Method Description
setLogFile Specifies the default path to the SDK log file.
setLogFilter Sets the output log level of the SDK.
setLogFileSize Sets the log file size in KB.
getSdkVersion Gets the SDK version.

Customized method

Method Description
setParameters Provides the technical preview functionalities or special customizations by configuring the SDK with JSON options.