hyphenate_SDK4.0 4.8.0
hyphenate java IM SDK
|
Public Member Functions | |
synchronized void | init (Context context, EMOptions options) |
void | createAccount (String username, String password) throws HyphenateException |
void | login (String id, String password, @NonNull final EMCallBack callback) |
void | loginWithToken (String username, String token, @NonNull final EMCallBack callback) |
void | loginWithAgoraToken (String username, String agoraToken, @NonNull final EMCallBack callback) |
void | notifyTokenExpired (String response) |
void | renewToken (String newAgoraToken) |
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 | 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 () |
void | getUserTokenFromServer (final String username, final String password, final EMValueCallBack< String > callBack) |
boolean | isLoggedInBefore () |
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) |
List< EMDeviceInfo > | getLoggedInDevicesFromServer (String username, String password) throws HyphenateException |
List< EMDeviceInfo > | getLoggedInDevicesFromServerWithToken (@NonNull String username, @NonNull String token) throws HyphenateException |
void | kickDevice (String username, String password, String resource) throws HyphenateException |
void | kickDeviceWithToken (@NonNull String username, @NonNull String token, String resource) throws HyphenateException |
void | kickAllDevices (String username, String password) 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 () |
void | check (String username, String password, final CheckResultListener listener) |
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.
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.
listener | The connection status listener to add.
|
void com.hyphenate.chat.EMClient.addLogListener | ( | final EMLogListener | listener | ) |
Adds the log callback listener of SDK.
listener | The log callback listener, EMLogListener#onLog(String). |
void com.hyphenate.chat.EMClient.addMultiDeviceListener | ( | EMMultiDeviceListener | listener | ) |
Adds the multi-device listener.
listener | The 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. |
void com.hyphenate.chat.EMClient.changeAppkey | ( | String | appkey | ) | throws HyphenateException |
Update the App Key.
Note
appkey | The App Key, make sure to set the param. |
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).
ChatManager
class. 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).
ChatRoomManager
class. 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).
EMChatThreadManager
class. void com.hyphenate.chat.EMClient.check | ( | String | username, |
String | password, | ||
final CheckResultListener | listener | ||
) |
Checks the Chat service.
The service check process is as follows:
If an error occurs during the check, the check process will be interrupted.
username | The 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. |
password | The password. If a user account has logged in before, the password will be changed to the password of the logged-in user. |
listener | The 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.
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.
HyphenateException | A description of the cause of the exception if the method fails. |
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).
ContactManager
class. void com.hyphenate.chat.EMClient.createAccount | ( | String | username, |
String | password | ||
) | throws HyphenateException |
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.
username | The user ID. The maximum length is 64 characters. Ensure that you set this parameter. The user ID can contain characters of the following types:
|
password | The password. The maximum length is 64 characters. Ensure that you set this parameter. |
HyphenateException | A description of the issue that caused this call to fail. For example, the user account or password is null, or the account is illegal. |
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
.
synchronized String com.hyphenate.chat.EMClient.getCurrentUser | ( | ) |
Gets the user ID of the current logged-in user.
List< EMDeviceInfo > com.hyphenate.chat.EMClient.getLoggedInDevicesFromServer | ( | String | username, |
String | password | ||
) | throws HyphenateException |
Gets the list of online devices where a specified user is logged in.
This is a synchronous method and blocks the current thread.
username | The user ID. |
password | The password. |
HyphenateException | A description of the exception. See EMError. |
List< EMDeviceInfo > com.hyphenate.chat.EMClient.getLoggedInDevicesFromServerWithToken | ( | @NonNull String | username, |
@NonNull String | token | ||
) | throws HyphenateException |
Gets the list of online devices where a specified user is logged in.
This is a synchronous method and blocks the current thread.
username | The user ID. |
token | The user token. |
HyphenateException | A description of the exception. See EMError. |
EMOptions com.hyphenate.chat.EMClient.getOptions | ( | ) |
Gets configuration options of the SDK.
void com.hyphenate.chat.EMClient.getUserTokenFromServer | ( | final String | username, |
final String | password, | ||
final EMValueCallBack< String > | callBack | ||
) |
Get a token by using the user ID and password.
username | The user ID. |
password | The password. |
callBack | The result callbackļ¼
|
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).
GroupManager
class. synchronized void com.hyphenate.chat.EMClient.init | ( | Context | context, |
EMOptions | options | ||
) |
Initializes the SDK.
Make sure to initialize the SDK in the main thread.
context | The context. Make sure to set the parameter. |
options | The configuration options. Make sure to set the parameter. See EMOptions. |
boolean com.hyphenate.chat.EMClient.isConnected | ( | ) |
Checks whether the SDK is connected to the chat server.
true
: Yes;false
: No. boolean com.hyphenate.chat.EMClient.isFCMAvailable | ( | ) |
Checks whether the FCM push is available.
true
: Yes;false
: No. boolean com.hyphenate.chat.EMClient.isLoggedIn | ( | ) |
Checks whether the user has logged in to the Chat app.
true
: Yes;false
: No. boolean com.hyphenate.chat.EMClient.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().
true
: The user has logged in before;false
: The user has not logged in before or has called the logout() method. boolean com.hyphenate.chat.EMClient.isSdkInited | ( | ) |
Checks whether the SDK is initialized.
true
: Yes.false
: No. void com.hyphenate.chat.EMClient.kickAllDevices | ( | String | username, |
String | password | ||
) | throws HyphenateException |
Kicks a user out of the app on all device.
This is a synchronous method and blocks the current thread.
username | The user ID. |
password | The password. |
HyphenateException | A description of the exception. See EMError. |
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.
username | The user ID. |
token | The user token. |
HyphenateException | A description of the exception. See EMError. |
void com.hyphenate.chat.EMClient.kickDevice | ( | String | username, |
String | password, | ||
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.
username | The user ID. |
password | The password. |
resource | The device ID. See EMDeviceInfo#getResource(). |
HyphenateException | A description of the exception if the method fails. See EMError. |
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.
username | The user ID. |
token | The user token. |
resource | The device ID. See EMDeviceInfo#getResource(). |
HyphenateException | A description of the exception if the method fails. See EMError. |
void com.hyphenate.chat.EMClient.login | ( | String | id, |
String | password, | ||
@NonNull final EMCallBack | callback | ||
) |
Logs in to the chat server with a password.
This is an asynchronous method.
id | The unique chat user ID. Make sure to set the parameter. |
password | The password. Make sure to set the parameter. |
callback | The login callback. Make sure to set the parameter. The login result is returned via the callback. |
void com.hyphenate.chat.EMClient.loginWithAgoraToken | ( | String | username, |
String | agoraToken, | ||
@NonNull final EMCallBack | 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, EMCallBack).
This an asynchronous method.
username | The user ID. Make sure to set the parameter. |
agoraToken | The Agora token. Make sure to set the parameter. |
callback | The login callback. Make sure to set the parameter. The result of login is returned via the callback. |
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 method supports automatic login.
You can also call login(String, String, EMCallBack) to log in to the chat server with the user ID and password.
This is an asynchronous method.
username | The user ID. Make sure to set the parameter. |
token | The user token. Make sure to set this parameter. |
callback | The login callback. Make sure to set the parameter. Also, this parameter cannot be null . The result of login is returned via the callback. |
int com.hyphenate.chat.EMClient.logout | ( | boolean | unbindToken | ) |
Logs out of the chat app.
This is a synchronous method and blocks the current thread.
unbindToken | Whether to unbind the token upon logout.
|
void com.hyphenate.chat.EMClient.logout | ( | final boolean | unbindToken, |
final EMCallBack | callback | ||
) |
Logs out of the chat server.
This is an asynchronous method.
unbindToken | Whether to unbind the token upon logout.
|
callback | The completion callback, which contains the error message if the method call fails. |
void com.hyphenate.chat.EMClient.notifyTokenExpired | ( | String | response | ) |
Notifies that the token expires.
The SDK triggers the token expiry notification callback via connectionListener.
response | The request result, which includes the description of the issue that cause the method fails. |
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).
PushManager
class. void com.hyphenate.chat.EMClient.removeConnectionListener | ( | final EMConnectionListener | listener | ) |
Removes the connection status listener.
listener | The connection status listener to remove. |
void com.hyphenate.chat.EMClient.removeLogListener | ( | final EMLogListener | listener | ) |
Removes the log callback listener.
listener | The log callback listener. |
void com.hyphenate.chat.EMClient.removeMultiDeviceListener | ( | EMMultiDeviceListener | listener | ) |
Removes the multi-device listener.
listener | The multi-device listener to remove. See EMMultiDeviceListener. |
void com.hyphenate.chat.EMClient.renewToken | ( | String | newAgoraToken | ) |
Renews the Agora token.
If you log in with an Agora 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.
newAgoraToken | The new token. |
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.
newToken | The new token. |
callback | renew token callback. Make sure to set the parameter. The result of renew token is returned via the callback. |
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:
fcmToken | The token to upload. |
void com.hyphenate.chat.EMClient.sendHMSPushTokenToServer | ( | String | token | ) |
Sends the HUAWEI Push token to the server.
token | The Huawei Push token. |
void com.hyphenate.chat.EMClient.sendHonorPushTokenToServer | ( | String | token | ) |
Sends the Honor Push token to the server.
token | The Honor Push token. |
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).
debugMode | Whether to output the debug information:
|
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.
callback | Reserved parameter. |
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).
EMUserInfoManager
class.