hyphenate_SDK3.0  3.8.6.1
hyphenate java IM SDK
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
com.hyphenate.chat.EMClient Class Reference

Classes

interface  AppStateListener
 
interface  CheckResultListener
 
class  MyConnectionListener
 
class  MyMultiDeviceListener
 

Public Member Functions

void init (Context context, EMOptions options)
 
void createAccount (String username, String password) throws HyphenateException
 
void login (String id, String password, final EMCallBack callback) throws IllegalArgumentException
 
void loginWithToken (String username, String token, final EMCallBack callback)
 
int logout (boolean unbindToken)
 
void logout (final boolean unbindToken, final EMCallBack callback)
 
void changeAppkey (String appkey) throws HyphenateException
 
void addConnectionListener (final EMConnectionListener listener)
 
void removeConnectionListener (final EMConnectionListener listener)
 
EMGroupManager groupManager ()
 
EMPushManager pushManager ()
 
EMChatRoomManager chatroomManager ()
 
EMChatManager chatManager ()
 
EMUserInfoManager userInfoManager ()
 
EMContactManager contactManager ()
 
Context getContext ()
 
synchronized String getCurrentUser ()
 
void getUserTokenFromServer (final String username, final String password, final EMValueCallBack< String > callBack)
 
boolean isLoggedInBefore ()
 
boolean isConnected ()
 
void setDebugMode (boolean debugMode)
 
boolean updateCurrentUserNick (String nickname) throws IllegalArgumentException, HyphenateException
 
void uploadLog (EMCallBack callback)
 
EMOptions getOptions ()
 
String compressLogs () throws HyphenateException
 
void addMultiDeviceListener (EMMultiDeviceListener listener)
 
void removeMultiDeviceListener (EMMultiDeviceListener listener)
 
List< EMDeviceInfogetLoggedInDevicesFromServer (String username, String password) throws HyphenateException
 
void kickDevice (String username, String password, String resource) throws HyphenateException
 
void kickAllDevices (String username, String password) throws HyphenateException
 
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 EMClient getInstance ()
 

Static Public Attributes

static final String TAG = "EMClient"
 
static final String VERSION = "3.8.6.1"
 

Detailed Description

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

 EMChatManager chatManager = EMClient.getInstance().chatManager();

Member Function Documentation

◆ addConnectionListener()

void com.hyphenate.chat.EMClient.addConnectionListener ( final EMConnectionListener  listener)

Add chat server connection listener

Parameters
listenerChat server connection listener EMConnectionListener#onConnected() indicates a successful connection to chat server EMConnectionListener#onDisconnected(int) indicates a failure connection to chat server, the parameter means the error code, see EMError

◆ addMultiDeviceListener()

void com.hyphenate.chat.EMClient.addMultiDeviceListener ( EMMultiDeviceListener  listener)

add multiple devices listener

Parameters
listenerSee EMMultiDeviceListener, EMMultiDeviceListener#onContactEvent(int, String, String) is the contact event callback, EMMultiDeviceListener#onGroupEvent(int, String, List) is the group event callback

◆ changeAppkey()

void com.hyphenate.chat.EMClient.changeAppkey ( String  appkey) throws HyphenateException

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

Parameters
appkeyNot be null or ""

◆ chatManager()

EMChatManager com.hyphenate.chat.EMClient.chatManager ( )

Gets chat manager, calls it after EMClient has been initialized, see init(Context, EMOptions)

Returns
The chat manager

◆ chatroomManager()

EMChatRoomManager com.hyphenate.chat.EMClient.chatroomManager ( )

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

Returns
The chat room manager

◆ check()

void com.hyphenate.chat.EMClient.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.

◆ compressLogs()

String com.hyphenate.chat.EMClient.compressLogs ( ) throws HyphenateException

Compress log folder into zip file, return zip file path

Returns
The path of compressed gz file
Exceptions
HyphenateExceptionThe exception by Compress gz file

◆ contactManager()

EMContactManager com.hyphenate.chat.EMClient.contactManager ( )

Gets contact manager, calls it after EMClient has been initialized, see init(Context, EMOptions)

Returns
The contact manager

◆ createAccount()

void com.hyphenate.chat.EMClient.createAccount ( String  username,
String  password 
) throws HyphenateException

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
HyphenateExceptionIf user account or password is null, or account is illegal will throw exception. The exception while registering account will be thrown here.

◆ getAccessToken()

String com.hyphenate.chat.EMClient.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 EMOptions#getAccessToken(). If you want to get token from server, can call EMOptions#getAccessToken(boolean) and enter true

Returns
Access token

◆ getCurrentUser()

synchronized String com.hyphenate.chat.EMClient.getCurrentUser ( )

Gets current login user ID

Returns
current login user

◆ getLoggedInDevicesFromServer()

List<EMDeviceInfo> com.hyphenate.chat.EMClient.getLoggedInDevicesFromServer ( String  username,
String  password 
) throws HyphenateException

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
HyphenateExceptionSee EMError

◆ getOptions()

EMOptions com.hyphenate.chat.EMClient.getOptions ( )

Gets EMOptions

◆ getUserTokenFromServer()

void com.hyphenate.chat.EMClient.getUserTokenFromServer ( final String  username,
final String  password,
final EMValueCallBack< String >  callBack 
)

Fetch token by username and password

Parameters
usernameThe registered username
passwordTODO: check
callBackResult callback EMValueCallBack#onSuccess(Object) indicates a successful callback,the parameter in onSuccess is the result of token EMValueCallBack#onError(int, String) indicates a failure callback, the first parameter is the error code, the second parameter is the error description

◆ groupManager()

EMGroupManager com.hyphenate.chat.EMClient.groupManager ( )

Gets group manager, calls it after EMClient has been initialized, see init(Context, EMOptions)

Returns
The group manager

◆ init()

void com.hyphenate.chat.EMClient.init ( Context  context,
EMOptions  options 
)

Initialize the SDK Need initialize The SDK in main process

Parameters
contextNot be null
optionsConfigurations, not be null, see EMOptions

◆ isConnected()

boolean com.hyphenate.chat.EMClient.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

◆ isFCMAvailable()

boolean com.hyphenate.chat.EMClient.isFCMAvailable ( )

Check whether FCM push is available

Returns
Return true means the FCM push is available; return false means not available

◆ isLoggedInBefore()

boolean com.hyphenate.chat.EMClient.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(EMClient.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

◆ isSdkInited()

boolean com.hyphenate.chat.EMClient.isSdkInited ( )

Determine if the SDK has been initialized

Returns
Whether the SDK has been initialized

◆ kickAllDevices()

void com.hyphenate.chat.EMClient.kickAllDevices ( String  username,
String  password 
) throws HyphenateException

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
HyphenateExceptionError code see EMError

◆ kickDevice()

void com.hyphenate.chat.EMClient.kickDevice ( String  username,
String  password,
String  resource 
) throws HyphenateException

Forced to logout the specified logged in device under the specified account, resource: EMDeviceInfo#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 EMDeviceInfo#getResource()
Exceptions
HyphenateExceptionError code see EMError

◆ login()

void com.hyphenate.chat.EMClient.login ( String  id,
String  password,
final EMCallBack  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, EMCallBack)

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.

◆ loginWithToken()

void com.hyphenate.chat.EMClient.loginWithToken ( String  username,
String  token,
final EMCallBack  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, EMCallBack)

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

◆ logout() [1/2]

int com.hyphenate.chat.EMClient.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 EMError#EM_NO_ERROR, means successful logout; Other values are exit failure, see EMError

◆ logout() [2/2]

void com.hyphenate.chat.EMClient.logout ( final boolean  unbindToken,
final EMCallBack  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 EMCallBack#onSuccess() indicates a successful logout callback EMCallBack#onError(int, String) indicates a failure logout callback, the first parameter means the error code, see EMError, the second parameter means the error description

◆ pushManager()

EMPushManager com.hyphenate.chat.EMClient.pushManager ( )

Gets push manager, calls it after EMClient has been initialized, see init(Context, EMOptions)

Returns
The push manager

◆ removeConnectionListener()

void com.hyphenate.chat.EMClient.removeConnectionListener ( final EMConnectionListener  listener)

Remove chat server connection listener

Parameters
listenerChat server connection listener

◆ removeMultiDeviceListener()

void com.hyphenate.chat.EMClient.removeMultiDeviceListener ( EMMultiDeviceListener  listener)

remove multiple devices listener

Parameters
listenerSee EMMultiDeviceListener

◆ sendFCMTokenToServer()

void com.hyphenate.chat.EMClient.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 com.hyphenate.push.EMPushType#FCM,
You can set with EMOptions#setFCMNumber(String)
Parameters
fcmTokenThe token want to upload

◆ sendHMSPushTokenToServer() [1/2]

void com.hyphenate.chat.EMClient.sendHMSPushTokenToServer ( String  appId,
String  token 
)

Send Huawei devices token to server

Parameters
appIdHuawei appId
tokenHuawei device token @Deprecated Use sendHMSPushTokenToServer(String) for instead.

◆ sendHMSPushTokenToServer() [2/2]

void com.hyphenate.chat.EMClient.sendHMSPushTokenToServer ( String  token)

Send Huawei devices token to server

Parameters
tokenHuawei device token

◆ setDebugMode()

void com.hyphenate.chat.EMClient.setDebugMode ( boolean  debugMode)

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

Parameters
debugModeEnter true, SDK will output debug info, enter false will not output

◆ updateCurrentUserNick()

boolean com.hyphenate.chat.EMClient.updateCurrentUserNick ( String  nickname) throws IllegalArgumentException, HyphenateException

Updates current user's push nickname, which is used to display in the notification bar when pushing Now use EMPushManager#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 EMPushManager#updatePushNickname(String) instead

◆ uploadLog()

void com.hyphenate.chat.EMClient.uploadLog ( EMCallBack  callback)

upload local log file

Synchronization method block the current thread

Parameters
callbackNot use in here

◆ userInfoManager()

EMUserInfoManager com.hyphenate.chat.EMClient.userInfoManager ( )

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

Returns
The user info manager

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