agora_chat_SDK  3.8.2
agorajavachatSDK
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)
 
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 ()
 
Context getContext ()
 
synchronized String getCurrentUser ()
 
void getUserTokenFromServer (final String username, final String password, final ValueCallBack< String > callBack)
 
boolean isLoggedInBefore ()
 
boolean isConnected ()
 
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 ()
 
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 = "3.8.2"
 

Detailed Description

Chat SDK Client, entrance of SDK, used to login, logout, and get access chat modules, such as

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

Member Function Documentation

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

Add chat server connection listener

Parameters
listenerChat server connection listener ConnectionListener#onConnected() indicates a successful connection to chat server ConnectionListener#onDisconnected(int) indicates a failure connection to chat server, the parameter means the error code, see Error
void io.agora.chat.ChatClient.addMultiDeviceListener ( MultiDeviceListener  listener)

add multiple devices listener

Parameters
listenerSee MultiDeviceListener, MultiDeviceListener#onContactEvent(int, String, String) is the contact event callback, MultiDeviceListener#onGroupEvent(int, String, List) is the group event callback
void io.agora.chat.ChatClient.changeAppkey ( String  appkey) throws ChatException

Change appkey Can ONLY be changed if not logged in Also can set appkey by ChatOptions#setAppKey(String), need be set if not logged in

Parameters
appkeyNot be null or ""
ChatManager io.agora.chat.ChatClient.chatManager ( )

Gets chat manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The chat manager
ChatRoomManager io.agora.chat.ChatClient.chatroomManager ( )

Gets chat room manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

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

Service check interface, here is the schedule:

1.Validate the username and password user input.
2.Get dns list from server.
3.Get token from server.
4.Connect to the im server.
5.logout.(If call this method after user logged in, this step will not in schedule.)

If there is a error occurred during checking, this schedule will be broken.

Parameters
usernameUser 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.

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

Compress log folder into zip file, return zip file path

Returns
The path of compressed gz file
Exceptions
ChatExceptionThe exception by Compress gz file
ContactManager io.agora.chat.ChatClient.contactManager ( )

Gets contact manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The contact manager
void io.agora.chat.ChatClient.createAccount ( String  username,
String  password 
) throws ChatException

create an chat account on server

Synchronization method block the current thread

Parameters
usernameThe account you want to register, not be null, can be a letter/number/underline/ cross/English period, regular as "^[a-zA-Z0-9_.-]+$", other is not allowed. It will automatically be converted to lowercase if it is a capital letter. The username's length can not be longer than 64 bytes.
passwordThe password you want to register, not be null. The password's length can not be longer than 64 bytes.
Exceptions
ChatExceptionIf user account or password is null, or account is illegal will throw exception. The exception while registering account will be thrown here.
String io.agora.chat.ChatClient.getAccessToken ( )

Gets access token from memory When uploading or downloading attachment (voice, image, file and so on), the token should be added to the request header; It is null when any exceptions occurs You can detect whether it is a problem by determining if the token is null. If the token is null, you can open the EMLog file to see the exception

Also can get token by ChatOptions#getAccessToken(). If you want to get token from server, can call ChatOptions#getAccessToken(boolean) and enter true

Returns
Access token
synchronized String io.agora.chat.ChatClient.getCurrentUser ( )

Gets current login user ID

Returns
current login user
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

Synchronization method block the current thread

Parameters
usernameThe account you want to get device info
passwordThe account's password
Returns
The list of online devices
Exceptions
ChatExceptionSee Error
ChatOptions io.agora.chat.ChatClient.getOptions ( )
void io.agora.chat.ChatClient.getUserTokenFromServer ( final String  username,
final String  password,
final ValueCallBack< String >  callBack 
)

Fetch token by username and password

Parameters
usernameThe registered username
passwordTODO: check
callBackResult callback ValueCallBack#onSuccess(Object) indicates a successful callbackļ¼Œthe parameter in onSuccess is the result of token ValueCallBack#onError(int, String) indicates a failure callback, the first parameter is the error code, the second parameter is the error description
GroupManager io.agora.chat.ChatClient.groupManager ( )

Gets group manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The group manager
void io.agora.chat.ChatClient.init ( Context  context,
ChatOptions  options 
)

Initialize the SDK Need initialize The SDK in main process

Parameters
contextNot be null
optionsConfigurations, not be null, see ChatOptions
boolean io.agora.chat.ChatClient.isConnected ( )

Checks if connected to chat server.

Returns
Return the result whether connected to chat server true means that has connected to chat server false means that has not connected to chat server
boolean io.agora.chat.ChatClient.isFCMAvailable ( )

Check whether FCM push is available

Returns
Return true means the FCM push is available; return false means not available
boolean io.agora.chat.ChatClient.isLoggedInBefore ( )

Uses to check if user has been logged in before and did not logout If you need check if connected to server, please use isConnected()

if(ChatClient.getInstance().isLoggedInBefore()){
    // enter main activity
}else{
    // enter login activity
}
Returns
The result if has login before true means that has login before false means that has not login before or has called logout() method
void io.agora.chat.ChatClient.kickAllDevices ( String  username,
String  password 
) throws ChatException

Forced to logout all logged in devices under the specified account

Synchronization method block the current thread

Parameters
usernameThe account you want to kick all the devices
passwordThe account's password
Exceptions
ChatExceptionError code see Error
void io.agora.chat.ChatClient.kickDevice ( String  username,
String  password,
String  resource 
) throws ChatException

Forced to logout the specified logged in device under the specified account, resource: DeviceInfo#getResource()

Synchronization method block the current thread

Parameters
usernameThe account you want to kick a device off
passwordThe account's password
resourceThe device ID, see DeviceInfo#getResource()
Exceptions
ChatExceptionError code see Error
void io.agora.chat.ChatClient.login ( String  id,
String  password,
final CallBack  callback 
) throws IllegalArgumentException

Login to chat server by login id and password Login to chat server by login id and token, see loginWithToken(String, String, CallBack)

Asynchronously method

Parameters
idUnique chat Login ID Not be null
passwordPassword for this chat ID Not be null
callbackLogin callback Not be null, the result of login is returned via the callback
Exceptions
IllegalArgumentExceptionIf id, password, callback or appkey is null throws an exception.
void io.agora.chat.ChatClient.loginWithToken ( String  username,
String  token,
final CallBack  callback 
)

Login to chat server by login id and token Other method login to chat server by login id and token, see login(String, String, CallBack)

Asynchronously method

Parameters
usernameUnique chat Login ID Not be null
tokenPassword for this chat ID Not be null
callbackLogin callback Not be null, the result of login is returned via the callback
Exceptions
RuntimeExceptionIf appkey is null throws a RuntimeException
IllegalArgumentExceptionIf Id, token or callback is null throws an exception
int io.agora.chat.ChatClient.logout ( boolean  unbindToken)

logout and return the result

Synchronization method block the current thread

Parameters
unbindTokenwhether unbind token true means to unbind the device token when logout false means to not unbind the device token when logout
Returns
The return value is 0 Error#EM_NO_ERROR, means successful logout; Other values are exit failure, see Error
void io.agora.chat.ChatClient.logout ( final boolean  unbindToken,
final CallBack  callback 
)

Logout hyphenate chat server

Asynchronously method

Parameters
unbindTokenwhether unbind token true means to unbind the device token when logout false means to not unbind the device token when logout
callbackEMCallback CallBack#onSuccess() indicates a successful logout callback CallBack#onError(int, String) indicates a failure logout callback, the first parameter means the error code, see Error, the second parameter means the error description
PushManager io.agora.chat.ChatClient.pushManager ( )

Gets push manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The push manager
void io.agora.chat.ChatClient.removeConnectionListener ( final ConnectionListener  listener)

Remove chat server connection listener

Parameters
listenerChat server connection listener
void io.agora.chat.ChatClient.removeMultiDeviceListener ( MultiDeviceListener  listener)

remove multiple devices listener

Parameters
listenerSee MultiDeviceListener
void io.agora.chat.ChatClient.sendFCMTokenToServer ( String  fcmToken)

Upload the FCM token to chat server

The token can be uploaded when all the following conditions are met:
1.The token is not empty
2.User logged in
3.Device support google play service
4.Push type is FCM io.agora.push.PushType#FCM,
You can set with ChatOptions#setFCMNumber(String)
Parameters
fcmTokenThe token want to upload
void io.agora.chat.ChatClient.sendHMSPushTokenToServer ( String  appId,
String  token 
)

Send Huawei devices token to server

Parameters
appIdHuawei appId
tokenHuawei device token Use sendHMSPushTokenToServer(String) for instead.
void io.agora.chat.ChatClient.sendHMSPushTokenToServer ( String  token)

Send Huawei devices token to server

Parameters
tokenHuawei device token
void io.agora.chat.ChatClient.setDebugMode ( boolean  debugMode)

Sets whether output debug info, should calls after ChatClient has been initialized, see init(Context, ChatOptions) SDK will out put debug info if debugMode = true

Parameters
debugModeEnter true, SDK will output debug info, enter false will not output
boolean io.agora.chat.ChatClient.updateCurrentUserNick ( String  nickname) throws IllegalArgumentException, ChatException

Updates current user's push nickname, which is used to display in the notification bar when pushing Now use PushManager#updatePushNickname(String) instead Need to distinguish the nickname in user properties Recommended to update the push nickname to chat server after getting the user information from the user server; When the nickname of user information change, we need to update to chat server to prevent display discrepancies

Parameters
nicknameNot be null, the length is not more than 100 characters
Deprecated:
From V3.3.3, use PushManager#updatePushNickname(String) instead
void io.agora.chat.ChatClient.uploadLog ( CallBack  callback)

upload local log file

Synchronization method block the current thread

Parameters
callbackNot use in here
UserInfoManager io.agora.chat.ChatClient.userInfoManager ( )

Gets user info manager, calls it after ChatClient has been initialized, see init(Context, ChatOptions)

Returns
The user info manager

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