hyphenate_SDK4.0 5.0.0
hyphenate java IM SDK
 
Loading...
Searching...
No Matches
com.hyphenate.chat.EMClient Class Reference

Public Member Functions

synchronized void init (Context context, EMOptions options)
 
void loginWithToken (String username, String token, @NonNull final EMCallBack callback)
 
void notifyTokenExpired (String response)
 
void renewToken (String newToken, @NonNull EMCallBack callback)
 
int logout (boolean unbindToken)
 
void logout (final boolean unbindToken, final EMCallBack callback)
 
void changeAppkey (String appkey) throws HyphenateException
 
void changeAppId (String appId) throws HyphenateException
 
void addConnectionListener (final EMConnectionListener listener)
 
void removeConnectionListener (final EMConnectionListener listener)
 
void addLogListener (final EMLogListener listener)
 
void removeLogListener (final EMLogListener listener)
 
EMGroupManager groupManager ()
 
EMPushManager pushManager ()
 
EMChatRoomManager chatroomManager ()
 
EMChatManager chatManager ()
 
EMUserInfoManager userInfoManager ()
 
EMContactManager contactManager ()
 
EMChatThreadManager chatThreadManager ()
 
synchronized String getCurrentUser ()
 
boolean isConnected ()
 
boolean isLoggedIn ()
 
void setDebugMode (boolean debugMode)
 
void uploadLog (EMCallBack callback)
 
EMOptions getOptions ()
 
String compressLogs () throws HyphenateException
 
void addMultiDeviceListener (EMMultiDeviceListener listener)
 
void removeMultiDeviceListener (EMMultiDeviceListener listener)
 
void fetchLoggedInDevicesFromServerWithToken (@NonNull String username, @NonNull String token, EMValueCallBack< List< EMDeviceInfo > > callBack)
 
void kickDeviceWithToken (@NonNull String username, @NonNull String token, String resource) throws HyphenateException
 
void kickAllDevicesWithToken (@NonNull String username, @NonNull String token) throws HyphenateException
 
void sendFCMTokenToServer (String fcmToken)
 
void sendHMSPushTokenToServer (String token)
 
void sendHonorPushTokenToServer (String token)
 
boolean isFCMAvailable ()
 
String getAccessToken ()
 
boolean isSdkInited ()
 
boolean isDatabaseOpened ()
 
void asyncGetRTCTokenInfoWithChannelName (@Nullable String channelName, EMValueCallBack< EMRTCTokenInfo > callBack)
 
void asyncGetUserIdsWithRTCUids (List< Integer > uIds, EMValueCallBack< Map< Integer, String > > callBack)
 

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.

EMChatManager chatManager = EMClient.getInstance().chatManager();
Definition EMChatManager.java:103

Member Function Documentation

◆ addConnectionListener()

void com.hyphenate.chat.EMClient.addConnectionListener ( final EMConnectionListener 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 com.hyphenate.chat.EMClient.addLogListener ( final EMLogListener listener)

Adds the log callback listener of SDK.

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

◆ addMultiDeviceListener()

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

Adds the multi-device listener.

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

◆ asyncGetRTCTokenInfoWithChannelName()

void com.hyphenate.chat.EMClient.asyncGetRTCTokenInfoWithChannelName ( @Nullable String channelName,
EMValueCallBack< EMRTCTokenInfo > callBack )

Gets the Agora RTC token, token expiration time, and RTC UID matching the Agora Chat user ID according to the channel name (channelName).

You must enable the Agora RTC feature before calling this API.

If the channel name is set to null, an RTC token valid for all channels will be generated.

This is an asynchronous method.

Parameters
channelNameThe Agora RTC channel name.
callBackThe completion callback, which contains the RTC token, expiration time, and RTC UID. The error message is returned if this call fails.

◆ asyncGetUserIdsWithRTCUids()

void com.hyphenate.chat.EMClient.asyncGetUserIdsWithRTCUids ( List< Integer > uIds,
EMValueCallBack< Map< Integer, String > > callBack )

Gets the Agora Chat user IDs matching the Agora RTC UIDs.

This is an asynchronous method.

Parameters
uIdsThe Agora RTC UID list.
callBackThe completion callback, which contains the mapping between the Agora RTC UIDs and Agora Chat user IDs. The error message is returned if the method call fails.

◆ changeAppId()

void com.hyphenate.chat.EMClient.changeAppId ( String appId) throws HyphenateException

Updates the App ID.

Note
  • As this App ID controls access to the chat service for your app, you can only update the key when the current user logs out.
  • Updating the App ID means to switch to a new App ID.
  • You can retrieve the new App ID from the Console.
  • You can set App ID by calling EMOptions#setAppId(String) when you log out of the chat service.
Parameters
appIdThe unique identifier of the application, which cannot be empty.

◆ changeAppkey()

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

Updates 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 EMOptions#setAppKey(String) when you log out of the chat service.
Parameters
appkeyThe unique identifier of the application, which cannot be empty.

◆ chatManager()

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

Gets the ChatManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The ChatManager class.

◆ chatroomManager()

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

Gets the ChatRoomManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The ChatRoomManager class.

◆ chatThreadManager()

EMChatThreadManager com.hyphenate.chat.EMClient.chatThreadManager ( )

Gets the EMChatThreadManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The EMChatThreadManager class.

◆ compressLogs()

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

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
HyphenateExceptionA description of the cause of the exception if the method fails.

◆ contactManager()

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

Gets the ContactManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The ContactManager class.

◆ fetchLoggedInDevicesFromServerWithToken()

void com.hyphenate.chat.EMClient.fetchLoggedInDevicesFromServerWithToken ( @NonNull String username,
@NonNull String token,
EMValueCallBack< List< EMDeviceInfo > > callBack )

Gets the list of online devices where a specified user is logged in.

This is an asynchronous method, which replaces the former synchronous method getLoggedInDevicesFromServerWithToken.

Parameters
usernameThe user ID.
tokenThe user token.
callBackThe completion callback. If this call succeeds, calls EMValueCallBack#onSuccess(Object) with the list of online devices where the specified user is logged in; if this call fails, calls EMValueCallBack#onError(int, String).

◆ getAccessToken()

String com.hyphenate.chat.EMClient.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 EMOptions#getAccessToken(boolean) and passing true.

Returns
The access token.

◆ getCurrentUser()

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

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

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

◆ getOptions()

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

Gets configuration options of the SDK.

◆ groupManager()

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

Gets the GroupManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The GroupManager class.

◆ init()

synchronized void com.hyphenate.chat.EMClient.init ( Context context,
EMOptions 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 EMOptions.

◆ isConnected()

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

◆ isDatabaseOpened()

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

Whether a usable local database context is currently available.

This state only indicates that the local database has been opened successfully and local database APIs can be used. It does not mean online login success and does not replace isLoggedIn() or connection-state callbacks.

◆ isFCMAvailable()

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

Checks whether the FCM push is available.

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

◆ isLoggedIn()

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

◆ isSdkInited()

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

Checks whether the SDK is initialized.

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

◆ kickAllDevicesWithToken()

void com.hyphenate.chat.EMClient.kickAllDevicesWithToken ( @NonNull String username,
@NonNull String token ) throws HyphenateException

Kicks a user out of the app on all device.

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
tokenThe user token.
Exceptions
HyphenateExceptionA description of the exception. See EMError.

◆ kickDeviceWithToken()

void com.hyphenate.chat.EMClient.kickDeviceWithToken ( @NonNull String username,
@NonNull String token,
String resource ) throws HyphenateException

Kicks a user out of the app on a device.

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

This is a synchronous method and blocks the current thread.

Parameters
usernameThe user ID.
tokenThe user token.
resourceThe device ID. See EMDeviceInfo#getResource().
Exceptions
HyphenateExceptionA description of the exception if the method fails. See EMError.

◆ loginWithToken()

void com.hyphenate.chat.EMClient.loginWithToken ( String username,
String token,
@NonNull final EMCallBack callback )

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

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

◆ logout() [2/2]

void com.hyphenate.chat.EMClient.logout ( final boolean unbindToken,
final EMCallBack 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 com.hyphenate.chat.EMClient.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()

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

Gets the PushManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The PushManager class.

◆ removeConnectionListener()

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

Removes the connection status listener.

Parameters
listenerThe connection status listener to remove.

◆ removeLogListener()

void com.hyphenate.chat.EMClient.removeLogListener ( final EMLogListener listener)

Removes the log callback listener.

Parameters
listenerThe log callback listener.

◆ removeMultiDeviceListener()

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

Removes the multi-device listener.

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

◆ renewToken()

void com.hyphenate.chat.EMClient.renewToken ( String newToken,
@NonNull EMCallBack callback )

Renews the Agora token.

If you log in with a token and are notified by a callback method EMConnectionListener 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
newTokenThe new token.
callbackrenew token callback. Make sure to set the parameter. The result of renew token is returned via the callback.

◆ sendFCMTokenToServer()

void com.hyphenate.chat.EMClient.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 EMPushType#FCM.
Parameters
fcmTokenThe token to upload.

◆ sendHMSPushTokenToServer()

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

Sends the HUAWEI Push token to the server.

Parameters
tokenThe Huawei Push token.

◆ sendHonorPushTokenToServer()

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

Sends the Honor Push token to the server.

Parameters
tokenThe Honor Push token.

◆ setDebugMode()

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

Sets whether to output the debug information.

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

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

◆ uploadLog()

void com.hyphenate.chat.EMClient.uploadLog ( EMCallBack 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()

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

Gets the EMUserInfoManager class.

This method can be called only after the EMClient is initialized. See init(Context, EMOptions). If the SDK is not initialized, it will return null.

Returns
The EMUserInfoManager class.

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