Chat SDK for Android v1.2.1
agora java chat SDK
Public Member Functions | List of all members
io.agora.chat.ChatClient Class Reference

Public Member Functions

void init (Context context, ChatOptions options)
 
void createAccount (String username, String password) throws ChatException
 
void login (String id, String password, @NonNull final CallBack callback)
 
void loginWithToken (String username, String token, @NonNull final CallBack callback)
 
void loginWithAgoraToken (String username, String agoraToken, @NonNull final CallBack callback)
 
void notifyTokenExpired (String response)
 
void renewToken (String newAgoraToken)
 
int logout (boolean unbindToken)
 
void logout (final boolean unbindToken, final CallBack callback)
 
void changeAppkey (String appkey) throws ChatException
 
void addConnectionListener (final ConnectionListener listener)
 
void removeConnectionListener (final ConnectionListener listener)
 
void addLogListener (final ChatLogListener listener)
 
void removeLogListener (final ChatLogListener listener)
 
GroupManager groupManager ()
 
PushManager pushManager ()
 
ChatRoomManager chatroomManager ()
 
ChatManager chatManager ()
 
UserInfoManager userInfoManager ()
 
ContactManager contactManager ()
 
ChatThreadManager chatThreadManager ()
 
synchronized String getCurrentUser ()
 
void getUserTokenFromServer (final String username, final String password, final ValueCallBack< String > callBack)
 
boolean isLoggedInBefore ()
 
boolean isConnected ()
 
boolean isLoggedIn ()
 
void setDebugMode (boolean debugMode)
 
void uploadLog (CallBack callback)
 
ChatOptions getOptions ()
 
String compressLogs () throws ChatException
 
void addMultiDeviceListener (MultiDeviceListener listener)
 
void removeMultiDeviceListener (MultiDeviceListener listener)
 
List< DeviceInfogetLoggedInDevicesFromServer (String username, String password) throws ChatException
 
List< DeviceInfogetLoggedInDevicesFromServerWithToken (@NonNull String username, @NonNull String token) throws ChatException
 
void kickDevice (String username, String password, String resource) throws ChatException
 
void kickDeviceWithToken (@NonNull String username, @NonNull String token, String resource) throws ChatException
 
void kickAllDevices (String username, String password) throws ChatException
 
void kickAllDevicesWithToken (@NonNull String username, @NonNull String token) throws ChatException
 
void sendFCMTokenToServer (String fcmToken)
 
void sendHMSPushTokenToServer (String token)
 
void sendHonorPushTokenToServer (String token)
 
boolean isFCMAvailable ()
 
String getAccessToken ()
 
boolean isSdkInited ()
 
void check (String username, String password, final CheckResultListener listener)
 

Detailed Description

The chat client class, which is the entry of the chat SDK. It defines how to log in to and log out of the chat app and how to manage the connection between the SDK and the chat server.

ChatManager chatManager = ChatClient.getInstance().chatManager();

Member Function Documentation

◆ addConnectionListener()

void io.agora.chat.ChatClient.addConnectionListener ( final ConnectionListener  listener)

Adds a connection status listener.

The listener listens for the connection between the chat app and the chat server.

Parameters
listenerThe connection status listener to add.

◆ addLogListener()

void io.agora.chat.ChatClient.addLogListener ( final ChatLogListener  listener)

Adds the log callback listener of SDK.

Parameters
listenerThe log callback listener, ChatLogListener#onLog(String).

◆ addMultiDeviceListener()

void io.agora.chat.ChatClient.addMultiDeviceListener ( MultiDeviceListener  listener)

Adds the multi-device listener.

Parameters
listenerThe multi-device listener to add. See MultiDeviceListener. MultiDeviceListener#onContactEvent(int, String, String) is the contact event callback and MultiDeviceListener#onGroupEvent(int, String, List) is the group event callback.

◆ changeAppkey()

void io.agora.chat.ChatClient.changeAppkey ( String  appkey) throws ChatException

Update the App Key.

Note

  • As this key controls access to the chat service for your app, you can only update the key when the current user logs out.
  • Updating the App Key means to switch to a new App Key.
  • You can retrieve the new App Key from the Console.
  • You can set App Key by calling ChatOptions#setAppKey(String) when you log out of the chat service.
Parameters
appkeyThe App Key, make sure to set the param.

◆ chatManager()

ChatManager io.agora.chat.ChatClient.chatManager ( )

Gets the ChatManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The ChatManager class.

◆ chatroomManager()

ChatRoomManager io.agora.chat.ChatClient.chatroomManager ( )

Gets the ChatRoomManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The ChatRoomManager class.

◆ chatThreadManager()

ChatThreadManager io.agora.chat.ChatClient.chatThreadManager ( )

Gets the ChatThreadManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The ChatThreadManager class.

◆ check()

void io.agora.chat.ChatClient.check ( String  username,
String  password,
final CheckResultListener  listener 
)

Checks the Chat service.

The service check process is as follows:

  1. Validates the user ID and password.
  2. Gets the DNS list from the server.
  3. Gets the token from the server.
  4. Connects to the IM server.
  5. Logs out of the Chat app. (If a user logs in before the check, this step will be ignored.)

If an error occurs during the check, the check process will be interrupted.

Parameters
usernameThe user ID for the service check. If a user account has logged in before, this user ID will be changed to the logged-in user ID to avoid changes to the information of the current logged-in user account.
passwordThe password. If a user account has logged in before, the password will be changed to the password of the logged-in user.
listenerThe service check result callback.

Contains account-validation check, get-dns check, get-Token check, login check. So the EMAChatClient.CheckResultListener#onResult(int, int, String) callback will be called four times.

◆ compressLogs()

String io.agora.chat.ChatClient.compressLogs ( ) throws ChatException

Compresses the debug log file into a gzip archive.

It is strongly recommended that you delete this debug archive as soon as this method is called.

Returns
The path of the compressed gz file.
Exceptions
ChatExceptionA description of the cause of the exception if the method fails.

◆ contactManager()

ContactManager io.agora.chat.ChatClient.contactManager ( )

Gets the ContactManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The ContactManager class.

◆ createAccount()

void io.agora.chat.ChatClient.createAccount ( String  username,
String  password 
) throws ChatException

Adds a new user account.

This method is not recommended and you are advised to call the RESTful API.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. The user ID can contain characters of the following types:
  • 26 English letters (a-z).
  • 10 numbers (0-9).
  • "_", "-", "." The user ID is case-insensitive, so Aa and aa are the same user ID. The email address or the UUID of the user cannot be used as the user ID. You can also set this parameter with the regular expression ^[a-zA-Z0-9_-]+$.
passwordThe password. The maximum length is 64 characters. Ensure that you set this parameter.
Exceptions
ChatExceptionA description of the issue that caused this call to fail. For example, the user account or password is null, or the account is illegal.

◆ getAccessToken()

String io.agora.chat.ChatClient.getAccessToken ( )

Gets the access token from the memory.

When uploading or downloading an attachment (a voice, image, or file), you must add the token to the request header. The SDK returns null when any exception occurs.

If the token is null, you can check the EMLog file for the possible reason.

You can also get the token from the server by calling ChatOptions#getAccessToken(boolean) and passing true.

Returns
The access token.

◆ getCurrentUser()

synchronized String io.agora.chat.ChatClient.getCurrentUser ( )

Gets the user ID of the current logged-in user.

Returns
The user ID of the current logged-in user.

◆ getLoggedInDevicesFromServer()

List< DeviceInfo > io.agora.chat.ChatClient.getLoggedInDevicesFromServer ( String  username,
String  password 
) throws ChatException

Gets the list of online devices to which you have logged in with a specified account.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
passwordThe password.
Returns
The list of online devices.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ getLoggedInDevicesFromServerWithToken()

List< DeviceInfo > io.agora.chat.ChatClient.getLoggedInDevicesFromServerWithToken ( @NonNull String  username,
@NonNull String  token 
) throws ChatException

Gets the list of online devices to which you have logged in with a specified account.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
tokenThe token.
Returns
The list of online devices.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ getOptions()

ChatOptions io.agora.chat.ChatClient.getOptions ( )

Gets configuration options of the SDK.

◆ getUserTokenFromServer()

void io.agora.chat.ChatClient.getUserTokenFromServer ( final String  username,
final String  password,
final ValueCallBack< String >  callBack 
)

Get a token by using the user ID and password.

Parameters
usernameThe user ID.
passwordThe password.
callBackThe result callbackļ¼š

◆ groupManager()

GroupManager io.agora.chat.ChatClient.groupManager ( )

Gets the GroupManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The GroupManager class.

◆ init()

void io.agora.chat.ChatClient.init ( Context  context,
ChatOptions  options 
)

Initializes the SDK.

Make sure to initialize the SDK in the main thread.

Parameters
contextThe context. Make sure to set the parameter.
optionsThe configuration options. Make sure to set the parameter. See ChatOptions.

◆ isConnected()

boolean io.agora.chat.ChatClient.isConnected ( )

Checks whether the SDK is connected to the chat server.

Returns
Whether the SDK is connected to the chat server.
  • true: Yes;
  • false: No.

◆ isFCMAvailable()

boolean io.agora.chat.ChatClient.isFCMAvailable ( )

Checks whether the FCM push is available.

Returns
Whether the FCM push is available:
  • true: Yes;
  • false: No.

◆ isLoggedIn()

boolean io.agora.chat.ChatClient.isLoggedIn ( )

Checks whether the user has logged in to the Chat app.

Returns
Whether the user has logged in to the Chat app.
  • true: Yes;
  • false: No.

◆ isLoggedInBefore()

boolean io.agora.chat.ChatClient.isLoggedInBefore ( )

Checks whether the user has logged in before.

This method always returns true if you log in successfully and have not called the logout() method yet.

If you need to check whether the SDK is connected to the server, call isConnected().

if(ChatClient.getInstance().isLoggedInBefore()){
// Enter the main activity.
}else{
// Enter the login activity.
}
Returns
Whether the user has logged in before.
  • true: The user has logged in before;
  • false: The user has not logged in before or has called the logout() method.

◆ isSdkInited()

boolean io.agora.chat.ChatClient.isSdkInited ( )

Checks whether the SDK is initialized.

Returns
Whether the SDK is initialized:
  • true: Yes.
  • false: No.

◆ kickAllDevices()

void io.agora.chat.ChatClient.kickAllDevices ( String  username,
String  password 
) throws ChatException

Logs out from a specified account on all devices.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
passwordThe password.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ kickAllDevicesWithToken()

void io.agora.chat.ChatClient.kickAllDevicesWithToken ( @NonNull String  username,
@NonNull String  token 
) throws ChatException

Logs out from a specified account on all devices.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
tokenThe token.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ kickDevice()

void io.agora.chat.ChatClient.kickDevice ( String  username,
String  password,
String  resource 
) throws ChatException

Logs out from a specified account on a device.

You can call DeviceInfo#getResource() to get the device ID.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
passwordThe password.
resourceThe device ID. See DeviceInfo#getResource().
Exceptions
ChatExceptionA description of the exception if the method fails, see Error.

◆ kickDeviceWithToken()

void io.agora.chat.ChatClient.kickDeviceWithToken ( @NonNull String  username,
@NonNull String  token,
String  resource 
) throws ChatException

Logs out from a specified account on a device.

You can call DeviceInfo#getResource() to get the device ID.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
tokenThe token.
resourceThe device ID. See DeviceInfo#getResource().
Exceptions
ChatExceptionA description of the exception if the method fails, see Error.

◆ login()

void io.agora.chat.ChatClient.login ( String  id,
String  password,
@NonNull final CallBack  callback 
)

Logs in to the chat server with a password.

Also, you can call loginWithToken(String, String, CallBack) to log in to the chat server with the user ID and token.

This is an asynchronous method.

Parameters
idThe unique chat user ID. Make sure to set the parameter.
passwordThe password. Make sure to set the parameter.
callbackThe login callback. Make sure to set the parameter. The login result is returned via the callback.

◆ loginWithAgoraToken()

void io.agora.chat.ChatClient.loginWithAgoraToken ( String  username,
String  agoraToken,
@NonNull final CallBack  callback 
)

Logs in to the chat server with the user ID and Agora token.

This method supports automatic login.

An app user can also log in to the chat server with the user ID and token. See login(String, String, CallBack).

This an asynchronous method.

Parameters
usernameThe user ID. Make sure to set the parameter.
agoraTokenThe Agora token. Make sure to set the parameter.
callbackThe login callback. Make sure to set the parameter. The result of login is returned via the callback.

◆ loginWithToken()

void io.agora.chat.ChatClient.loginWithToken ( String  username,
String  token,
@NonNull final CallBack  callback 
)

Logs in to the chat server with the user ID and token.

This method supports automatic login.

You can also call login(String, String, CallBack) to log in to the chat server with the user ID and password.

This is an asynchronous method.

Parameters
usernameThe user ID. Make sure to set the parameter.
tokenThe user token. Make sure to set this parameter.
callbackThe login callback. Make sure to set the parameter. Also, this parameter cannot be null. The result of login is returned via the callback.

◆ logout() [1/2]

int io.agora.chat.ChatClient.logout ( boolean  unbindToken)

Logs out of the chat app.

This is a synchronous method and blocks the current thread.

Parameters
unbindTokenWhether to unbind the token upon logout.
  • true: Yes.
  • false: No.
Returns
The logout result.
  • If success, the SDK returns Error#EM_NO_ERROR if the user successfully logs out;
  • If a failure occurs, the SDK returns the description of the cause to the failure. See Error.

◆ logout() [2/2]

void io.agora.chat.ChatClient.logout ( final boolean  unbindToken,
final CallBack  callback 
)

Logs out of the chat server.

This is an asynchronous method.

Parameters
unbindTokenWhether to unbind the token upon logout.
  • true: Yes;
  • false: No.
callbackThe completion callback, which contains the error message if the method call fails.

◆ notifyTokenExpired()

void io.agora.chat.ChatClient.notifyTokenExpired ( String  response)

Notifies that the token expires.

The SDK triggers the token expiry notification callback via connectionListener.

Parameters
responseThe request result, which includes the description of the issue that cause the method fails.

◆ pushManager()

PushManager io.agora.chat.ChatClient.pushManager ( )

Gets the PushManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The PushManager class.

◆ removeConnectionListener()

void io.agora.chat.ChatClient.removeConnectionListener ( final ConnectionListener  listener)

Removes the connection status listener.

Parameters
listenerThe connection status listener to remove.

◆ removeLogListener()

void io.agora.chat.ChatClient.removeLogListener ( final ChatLogListener  listener)

Removes the log callback listener.

Parameters
listenerThe log callback listener.

◆ removeMultiDeviceListener()

void io.agora.chat.ChatClient.removeMultiDeviceListener ( MultiDeviceListener  listener)

Removes the multi-device listener.

Parameters
listenerThe multi-device listener to remove. See MultiDeviceListener.

◆ renewToken()

void io.agora.chat.ChatClient.renewToken ( String  newAgoraToken)

Renews the Agora token.

If you log in with an Agora token and are notified by a callback method ConnectionListener that the token is to be expired, you can call this method to update the token to avoid unknown issues caused by an invalid token.

Parameters
newAgoraTokenThe new token.

◆ sendFCMTokenToServer()

void io.agora.chat.ChatClient.sendFCMTokenToServer ( String  fcmToken)

Uploads the FCM token to the chat server.

The token can be uploaded when the following conditions are met:

  • The token is not empty;
  • The user has logged in to the Chat app;
  • The current device supports Google PUSH service;
  • The push type is FCM PushType#FCM.
Parameters
fcmTokenThe token to upload.

◆ sendHMSPushTokenToServer()

void io.agora.chat.ChatClient.sendHMSPushTokenToServer ( String  token)

Sends the HUAWEI Push token to the server.

Parameters
tokenThe Huawei Push token.

◆ sendHonorPushTokenToServer()

void io.agora.chat.ChatClient.sendHonorPushTokenToServer ( String  token)

Sends the Honor Push token to the server.

Parameters
tokenThe Honor Push token.

◆ setDebugMode()

void io.agora.chat.ChatClient.setDebugMode ( boolean  debugMode)

Sets whether to output the debug information.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Parameters
debugModeWhether to output the debug information:
  • true: Yes;
  • false: No.

◆ uploadLog()

void io.agora.chat.ChatClient.uploadLog ( CallBack  callback)

Uploads local logs.

The debug logs provide reference for our engineers to fix errors and improve system performance.

This is a synchronous method and blocks the current thread.

Parameters
callbackReserved parameter.

◆ userInfoManager()

UserInfoManager io.agora.chat.ChatClient.userInfoManager ( )

Gets the UserInfoManager class.

This method can be called only after the ChatClient is initialized. See init(Context, ChatOptions).

Returns
The UserInfoManager class.

The documentation for this class was generated from the following file: