agora_chat_SDK 1.0.6
agora java chat SDK
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
io.agora.chat.ChatClient Class Reference

Classes

interface  AppStateListener
 
interface  CheckResultListener
 
class  MyConnectionListener
 
class  MyMultiDeviceListener
 

Public Member Functions

void init (Context context, ChatOptions options)
 
void createAccount (String username, String password) throws ChatException
 
void login (String id, String password, final CallBack callback) throws IllegalArgumentException
 
void loginWithToken (String username, String token, final CallBack callback)
 
void loginWithAgoraToken (String username, String agoraToken, 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)
 
GroupManager groupManager ()
 
PushManager pushManager ()
 
ChatRoomManager chatroomManager ()
 
ChatManager chatManager ()
 
UserInfoManager userInfoManager ()
 
ContactManager contactManager ()
 
TranslationManager translationManager ()
 
PresenceManager presenceManager ()
 
ChatThreadManager chatThreadManager ()
 
Context getContext ()
 
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)
 
boolean updateCurrentUserNick (String nickname) throws IllegalArgumentException, ChatException
 
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
 
void kickDevice (String username, String password, String resource) throws ChatException
 
void kickAllDevices (String username, String password) throws ChatException
 
void sendFCMTokenToServer (String fcmToken)
 
void sendHMSPushTokenToServer (String appId, String token)
 
void sendHMSPushTokenToServer (String token)
 
boolean isFCMAvailable ()
 
String getAccessToken ()
 
boolean isSdkInited ()
 
EMChatConfigPrivate getChatConfigPrivate ()
 
JSONObject getDeviceInfo ()
 
void check (String username, String password, final CheckResultListener listener)
 

Static Public Member Functions

static ChatClient getInstance ()
 

Static Public Attributes

static final String TAG = "ChatClient"
 
static final String VERSION = "1.0.6"
 

Detailed Description

The ChatClient, which is the entry point of the Chat SDK. You can log in, log out, and access other functionalities such as group and chatroom with this class.

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

Member Function Documentation

◆ addConnectionListener()

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

Adds the connection listener of chat server.

Parameters
listenerThe chat server connection listener. ConnectionListener#onConnected() indicates a successful connection to chat server, ConnectionListener#onDisconnected(int) indicates a failure connection to chat server, it contains the error code, see Error.

◆ addMultiDeviceListener()

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

Adds the multi-device listener.

Parameters
listenerSee MultiDeviceListener, MultiDeviceListener#onContactEvent(int, String, String) is the contact event callback, 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, which is the unique identifier used to access Agora Chat.

You retrieve the new App Key from Agora Console.

As this key controls all access to Agora Chat for your app, you can only update the key when the current user is logged out.

Also, you can set App Key by the following method when logged out ChatOptions#setAppKey(String).

Parameters
appkeyThe App Key, make sure to set the param.

◆ chatManager()

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

Gets the ChatManager class. Make sure to call it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The ChatManager class.

◆ chatroomManager()

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

Gets the ChatRoomManager class. Make sure to call it after the ChatClient has been initialized, see init(Context, ChatOptions).

Returns
The ChatRoomManager class.

◆ chatThreadManager()

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

Gets the ChatThreadManager class. Make sure to call it after ChatClient has been initialized, see init(Context, ChatOptions).

Returns
The ChatThreadManager class.

◆ check()

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

The service check interface. The schedule is as follows:

1.Validates the username and password user input. 2.Gets the dns list from the server. 3.Gets the token from the server. 4.Connects to the im server. 5.Logout.(If you call this method after the user logged in, this step will not be in the schedule.)

If there is a error occurs during checking, this schedule will be interrupted.

Parameters
usernameThe user inputted for service check. If account has logged in before, this username would be changed to the logged in username to avoid update the current logged in account data.
passwordThe password for username. if this is a logged in service check, the password would changed to the logged in password.
listenerA listener for service check results 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 into a gzip archive. Best practice is to delete this debug archive as soon as it is no longer used.

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. Make sure to call it after the ChatClient has been initialized, see init(Context, ChatOptions).

Returns
The ContactManager class.

◆ createAccount()

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

Register a new user with your chat network.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe username. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[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 attachment (voice, image, file and so on), the token should be added to the request header;

The SDK returns null when any exceptions occurs.

You can detect whether there is a exception by check the token. If the token is null, you can check the EMLog file to find the exception.

You can also get token by calling ChatOptions#getAccessToken(boolean) and enter true.

Returns
The access token.

◆ getCurrentUser()

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

Gets the current login user ID.

Returns
The current login user ID.

◆ getLoggedInDevicesFromServer()

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

Gets all the information about the logged in devices under the specified account.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID you want to get the device information.
passwordThe password.
Returns
The list of the online devices.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ getOptions()

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

Gets ChatOptions.

◆ getUserTokenFromServer()

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

Fetches token by username and password.

Parameters
usernameThe registered username.
passwordThe password.
callBackThe result callback:

◆ groupManager()

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

Gets the GroupManager class. Be sure to call it after the ChatClient has been 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
contextMake sure to set the param.
optionsThe configurations. Make sure to set the param, see ChatOptions.

◆ isConnected()

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

Checks whether the SDK is connected to the chat server.

Returns
Returns the result whether the SDK is connected to the chat server.
  • true means that the SDK is connected to the chat server.
  • false means not.

◆ isFCMAvailable()

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

Checks whether the FCM push is available.

Returns
- true: the FCM push is available;
  • false: not available.

◆ isLoggedIn()

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

Checks whether the user is logged in.

Returns
Returns the result of whether the user has logged in.
  • true indicates that the user has logged in;
  • false indicates not.

◆ isLoggedInBefore()

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

Checks whether the user has logged in before and did not log out.

Reference: If you need to check whether the SDK is connected to the server, please use isConnected().

if(ChatClient.getInstance().isLoggedInBefore()){
// Enter the main activity.
}else{
// Enter the login activity.
}
Returns
The result of whether the user has logged in before.
  • true means that the user has logged in before,
  • false means that the user has not login before or has called logout() method.

◆ isSdkInited()

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

Checks whether the SDK has been initialized.

Returns
- true: The SDK has been initialized.
  • false: The SDK has not been initialized.

◆ kickAllDevices()

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

Kicks out all the devices logged in under the specified account.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe account you want to log out from all the devices.
passwordThe account's password.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ kickDevice()

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

Force the specified account to logout from the specified device, to fetch the device ID: DeviceInfo#getResource().

This is a synchronous method and blocks the current thread.

Parameters
usernameThe account you want to force logout.
passwordThe account's password.
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,
final CallBack  callback 
) throws IllegalArgumentException

An app user logs in to the chat server with a password.

Reference: An app user logs in to to the chat server by user ID and token, see loginWithToken(String, String, CallBack).

This is an asynchronous method.

Parameters
idThe unique chat user ID, the same as username. Make sure to set the param.
passwordThe password. Make sure to set the param.
callbackThe login callback. Make sure to set the param. The result is returned via the callback.
Exceptions
IllegalArgumentExceptionA description of the issue that caused this call to fail. For example, the user ID, password, callback or App Key is null.

◆ loginWithAgoraToken()

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

An app user logs in to the chat server by user ID and Agora token. This method supports automatic login.

Reference: Another method to login to chat server is to login with user ID and token, see login(String, String, CallBack).

This an asynchronous method.

Parameters
usernameThe user ID. Make sure to set the param.
agoraTokenThe Agora token. Make sure to set the param.
callbackThe callback. Make sure to set the param. The result of login is returned via the callback.
Exceptions
RuntimeExceptionIf the App Key is null, the SDK will throws a RuntimeException.
IllegalArgumentExceptionA description of the exception. For example, the user ID, AgoraToken or callback is null.

◆ loginWithToken()

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

An app user logs in to the chat server by user ID and token.

Reference: There is another method to login to the chat server, which is by user ID and password, see login(String, String, CallBack).

This is an asynchronous method.

Parameters
usernameThe user ID. Make sure to set the param.
tokenThe password for this user ID. Make sure to set the param.
callbackThe login callback. Make sure to set the param. The result of login is returned via the callback.
Exceptions
RuntimeExceptionIf the app key is null, the SDK throws a RuntimeException.
IllegalArgumentExceptionA description of the issue that caused this call to fail. For example, the ID, token or callback is null.

◆ logout() [1/2]

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

An app user logs out and returns the result.

This is a synchronous method and blocks the current thread.

Parameters
unbindTokenWhether to unbind the token.
  • true means to unbind the device token when logout.
  • false means to not unbind the device token when logout.
Returns
- Returns Error#EM_NO_ERROR if the user successfully logs out.
  • Or 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 
)

An app user logs out the chat server.

This is an asynchronous method.

Parameters
unbindTokenWhether to unbind token.
  • true means to unbind the device token when logout.
  • false means to not unbind the device token when logout.
callbackThe completion callback, which contains the error message if the method fails.

◆ notifyTokenExpired()

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

The notification that the token is expired, will be called back to the connectionListener expiration event through ChatClient.

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. Be sure to call it after the ChatClient has been initialized, see init(Context, ChatOptions).

Returns
The PushManager class.

◆ removeConnectionListener()

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

Removes the chat server connection listener.

Parameters
listenerThe chat server connection listener.

◆ removeMultiDeviceListener()

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

Removes the multi-device listener.

Parameters
listenerSee MultiDeviceListener.

◆ renewToken()

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

When a user is in the Agora token login state and receives a callback notification of the token is to be expired in the ConnectionListener implementation class, this API can be called to update the token to avoid unknown problems caused by the token invalidation.

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 all the following conditions are met: 1.The token is not empty; 2.The user have logged in; 3.The device support Google PUSH service; 4.The push type is FCM io.agora.push.PushType#FCM.

You can set with ChatOptions#setFCMNumber(String).

Parameters
fcmTokenThe token you want to upload.

◆ sendHMSPushTokenToServer() [1/2]

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

Sends the Huawei devices token to the server.

Parameters
appIdThe Huawei appId.
tokenThe Huawei device token. @Deprecated Please use sendHMSPushTokenToServer(String) instead.

◆ sendHMSPushTokenToServer() [2/2]

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

Sends the Huawei devices token to the server.

Parameters
tokenThe Huawei device token.

◆ setDebugMode()

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

Sets whether to output the debug info. Make sure to call the method after the ChatClient has been initialized, see init(Context, ChatOptions).

The SDK will out put debug info if you set the debugMode as true.

Parameters
debugMode- true: The SDK will output the debug info;
  • false: Do not output the debug info.

◆ updateCurrentUserNick()

boolean io.agora.chat.ChatClient.updateCurrentUserNick ( String  nickname) throws IllegalArgumentException, ChatException

Updates the current user's push notification display nickname, which is used to display in the notification bar when pushing.

Deprecated:
From V3.3.3, use PushManager#updatePushNickname(String) instead.

Notice that the nickname in user profiles is different from this PushNickname.

We recommend you to update the push notification display nickname to the chat server after getting the user information from the user server; When the nickname of user information change, make sure to update to the chat server to prevent display discrepancies.

Parameters
nicknameMake sure to set the param, the data length is not more than 100 characters.

◆ uploadLog()

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

Uploads local log file.

The information in the debug log is used by 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. Make sure to call it after ChatClient has been initialized, see init(Context, ChatOptions).

Returns
The UserInfoManager class.

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