Core class of the IM SDK, implementing features such as IM SDK initialization and login, message sending and receiving, and group creation and quitting
|
abstract boolean | initSDK (Context context, int sdkAppID, V2TIMSDKConfig config) |
|
abstract void | unInitSDK () |
|
abstract void | addIMSDKListener (V2TIMSDKListener listener) |
|
abstract void | removeIMSDKListener (V2TIMSDKListener listener) |
|
abstract String | getVersion () |
|
abstract long | getServerTime () |
|
abstract boolean | initSDK (Context context, int sdkAppID, V2TIMSDKConfig config, V2TIMSDKListener listener) |
|
abstract void | login (String userID, String userSig, V2TIMCallback callback) |
|
abstract void | logout (V2TIMCallback callback) |
|
abstract String | getLoginUser () |
|
abstract int | getLoginStatus () |
|
abstract void | addSimpleMsgListener (V2TIMSimpleMsgListener v2TIMSimpleMsgListener) |
|
abstract void | removeSimpleMsgListener (V2TIMSimpleMsgListener v2TIMSimpleMsgListener) |
|
abstract String | sendC2CTextMessage (String text, String userID, V2TIMValueCallback< V2TIMMessage > callback) |
|
abstract String | sendC2CCustomMessage (byte[] customData, String userID, V2TIMValueCallback< V2TIMMessage > callback) |
|
abstract String | sendGroupTextMessage (String text, String groupID, int priority, V2TIMValueCallback< V2TIMMessage > callback) |
|
abstract String | sendGroupCustomMessage (byte[] customData, String groupID, int priority, V2TIMValueCallback< V2TIMMessage > callback) |
|
abstract void | setGroupListener (V2TIMGroupListener listener) |
|
abstract void | addGroupListener (V2TIMGroupListener listener) |
|
abstract void | removeGroupListener (V2TIMGroupListener listener) |
|
abstract void | createGroup (String groupType, String groupID, String groupName, V2TIMValueCallback< String > callback) |
|
abstract void | joinGroup (String groupID, String message, V2TIMCallback callback) |
|
abstract void | quitGroup (String groupID, final V2TIMCallback callback) |
|
abstract void | dismissGroup (String groupID, final V2TIMCallback callback) |
|
abstract void | getUsersInfo (List< String > userIDList, V2TIMValueCallback< List< V2TIMUserFullInfo >> callback) |
|
abstract void | setSelfInfo (V2TIMUserFullInfo info, V2TIMCallback callback) |
|
abstract void | getUserStatus (List< String > userIDList, V2TIMValueCallback< List< V2TIMUserStatus >> callback) |
|
abstract void | setSelfStatus (V2TIMUserStatus status, V2TIMCallback callback) |
|
abstract void | subscribeUserStatus (List< String > userIDList, V2TIMCallback callback) |
|
abstract void | unsubscribeUserStatus (List< String > userIDList, V2TIMCallback callback) |
|
abstract void | callExperimentalAPI (String api, Object param, V2TIMValueCallback< Object > callback) |
|
◆ getInstance()
1.1 Get the V2TIMManager instance
◆ initSDK() [1/2]
abstract boolean initSDK |
( |
Context |
context, |
|
|
int |
sdkAppID, |
|
|
V2TIMSDKConfig |
config |
|
) |
| |
|
abstract |
1.2 Initialize the SDK
- Parameters
-
context | Context |
sdkAppID | App ID. This field is required. You can obtain the app ID from the console. |
config | Configuration information |
- Returns
- true: successful; false: failed. If context is empty, false is returned.
◆ unInitSDK()
abstract void unInitSDK |
( |
| ) |
|
|
abstract |
◆ addIMSDKListener()
◆ removeIMSDKListener()
◆ getVersion()
abstract String getVersion |
( |
| ) |
|
|
abstract |
1.6 Get the SDK version
- Returns
◆ getServerTime()
abstract long getServerTime |
( |
| ) |
|
|
abstract |
1.7 Get the current server time
- Returns
- Server time, in seconds
◆ initSDK() [2/2]
1.8 Initialize the SDK
- Parameters
-
context | Context |
sdkAppID | App ID. This field is required. You can obtain the app ID from the console. |
config | Configuration information |
listener | SDK callback |
- Returns
- true: successful; false: failed. If context is empty, false is returned.
◆ login()
abstract void login |
( |
String |
userID, |
|
|
String |
userSig, |
|
|
V2TIMCallback |
callback |
|
) |
| |
|
abstract |
2.1 Login
userID and userSig must be set for login. For the generation of userSig, please see UserSig backend API.
- Attention
- Note the following special logic:
- The ticket expires before login: the callback of the login function returns the error ERR_USER_SIG_EXPIRED (6206) or ERR_SVR_ACCOUNT_USERSIG_EXPIRED (70001), and the user needs to generate a new userSig and log in again.
- The ticket expires when the user is online: the user can receive the V2TIMListener -> onUserSigExpired callback when online, and the user also needs to generate a new userSig and log in again.
- An online user is kicked offline: the SDK notifies the user of the logout via the V2TIMListener -> onKickedOffline callback and displays the logout notification on the UI, and the user can call login() to log in again.
◆ logout()
2.2 Logout
If the user logs out and switches the account, the user can log in again after the logout function calls back success or failure. Otherwise, login may fail.
◆ getLoginUser()
abstract String getLoginUser |
( |
| ) |
|
|
abstract |
◆ getLoginStatus()
abstract int getLoginStatus |
( |
| ) |
|
|
abstract |
2.4 Get the login status
If the user is already in the "logged in" or "logging in" state, do not frequently call the login API to log in.
- Returns
- Login status
- V2TIM_STATUS_LOGINED: logged in
- V2TIM_STATUS_LOGINING: logging in
- V2TIM_STATUS_LOGOUT: logged out
◆ addSimpleMsgListener()
◆ removeSimpleMsgListener()
3.2 Remove the event listener for simple messages (text messages and custom messages)
◆ sendC2CTextMessage()
3.3 Send a one-to-one text message (up to 12 KB)
Text messages support sensitive word filtering on the cloud. For example, if a text message sent by a user contains sensitive words, the callback will return the 80001 error code.
- Returns
- Unique ID of the message
- Attention
- Messages sent via this API are pushed by default (provided that the push feature is enabled in V2TIMOfflinePushManager). If you need to customize the push (title and content), call the V2TIMMessageManager.sendMessage API.
◆ sendC2CCustomMessage()
3.4 Send a one-to-one custom (signaling) message (up to 12 KB)
A custom message is essentially a binary buffer on which you can freely organize your message format (often used to send signaling). However, custom messages do not support sensitive word filtering on the cloud.
- Returns
- Unique ID of the message
- Attention
- Messages sent via this API are not pushed by default. To push the messages, call the V2TIMMessageManager.sendMessage API.
◆ sendGroupTextMessage()
3.5 Send a group text message (up to 12 KB)
- Parameters
-
priority | Message priority. Though there is no way for all messages to 100% reach every user, higher-priority messages will have a higher delivery success rate.
- V2TIMMessage.V2TIM_PRIORITY_HIGH: the message will be transferred with high priority on the cloud. This setting is suitable for sending important messages in the group, such as text messages sent by host.
- V2TIMMessage.V2TIM_PRIORITY_NORMAL: the message will be transferred with the default priority on the cloud. This setting is suitable for sending unimportant messages in the group, such as on-screen comments sent by viewers.
|
- Returns
- Unique ID of the message
- Attention
- Messages sent via this API are pushed by default (provided that the push feature is enabled in V2TIMOfflinePushManager). If you need to customize the push (title and content), call the V2TIMMessageManager.sendMessage API.
◆ sendGroupCustomMessage()
3.6 Send a group custom (signaling) message (up to 12 KB)
- Parameters
-
priority | Message priority. Though there is no way for all messages to 100% reach every user, higher-priority messages will have a higher delivery success rate.
- V2TIMMessage.V2TIM_PRIORITY_HIGH: the message will be transferred with high priority on the cloud. This setting is suitable for sending important messages in the group, such as mic connect invitations, competition invitation, gift-giving, and other key signaling.
- V2TIMMessage.V2TIM_PRIORITY_NORMAL: the message will be transferred with the default priority on the cloud. This setting is suitable for sending unimportant signaling in the group, such as audience's like notifications.
|
- Returns
- Unique ID of the message
- Attention
- Messages sent via this API are not pushed by default. To push the messages, call the V2TIMMessageManager.sendMessage API.
◆ setGroupListener()
4.1 Set the group listener
◆ addGroupListener()
4.2 Add the group listener
◆ removeGroupListener()
4.3 Remove the group listener
◆ createGroup()
abstract void createGroup |
( |
String |
groupType, |
|
|
String |
groupID, |
|
|
String |
groupName, |
|
|
V2TIMValueCallback< String > |
callback |
|
) |
| |
|
abstract |
4.4 Create a group
- Parameters
-
groupType | Group type. The following several common group types are preset in the SDK. You can also customize desired group types in the console:
- Work group (Work): supports up to 200 members; does not allow proactive group joining and only allows users to be invited to join the group by group members; suitable for groups like work groups created in WeChat (corresponding to Private groups in the earlier version)
- Public group (Public): supports up to 2,000 members; allows anyone to apply to join the group, but requires group owner or admin approval for group joining; suitable for groups like interest groups managed by group owners in QQ
- Meeting group (Meeting): supports up to 6,000 members; allows anyone to join and leave the group freely, without approval; suitable for scenarios such as video conference and online training (corresponding to ChatRoom groups in the earlier version)
- Community : supports up to 100,000 members; allows anyone to join and leave the group freely, without approval; suitable for large community group chat scenarios such as knowledge sharing and game communication. supported only in 5.8 and later versions, need to buy Flagship Edition.
- Audio-video group (AVChatRoom): supports an unlimited number of members; allows anyone to join and leave the group freely; features high message throughput and is suitable for use as a chat room with high-concurrency on-screen comments in live streaming scenarios
|
groupID | Custom group ID. "null" can be passed in. When "null" is passed in, the system automatically assigns a group ID and calls back the group ID via callback. Custom group ID of "Community" must be prefixed with "@TGS#_". |
groupName | Group name. The value cannot be "null" and can contain up to 30 bytes. |
- Attention
- Note the following special logic:
- Do not create groups with the same group ID under the same SDKAppID.
- Audio-video group (AVChatRoom): After the process is restarted or logged in again, if you want to continue to receive messages from the Audio-video group, please call joinGroup to rejoin the Audio-video group.
◆ joinGroup()
abstract void joinGroup |
( |
String |
groupID, |
|
|
String |
message, |
|
|
V2TIMCallback |
callback |
|
) |
| |
|
abstract |
4.5 Join a group
- Attention
- Note the following special logic:
- Work group (Work): users cannot proactively join a Work group. Only group members can call the V2TIMManager.getGroupManager().inviteUserToGroup() API to invite users to join the group.
- Public group (Public): admin approval is required for users to join a Public group. When receiving the V2TIMGroupListener -> onReceiveJoinApplication callback, the admin needs to call the V2TIMManager.getGroupManager().getGroupApplicationList() API to handle group joining requests.
- Other groups: users can directly join such groups.
- Audio-video group (AVChatRoom): After the process is restarted or logged in again, if you want to continue to receive messages from the Audio-video group, please call joinGroup to rejoin the Audio-video group.
◆ quitGroup()
abstract void quitGroup |
( |
String |
groupID, |
|
|
final V2TIMCallback |
callback |
|
) |
| |
|
abstract |
4.6 Quit a group
- Attention
- For public groups (Public), meeting groups (Meeting), and audio-video groups (AVChatRoom), the group owner cannot quit the group and can only call dismissGroup to delete the group.
◆ dismissGroup()
abstract void dismissGroup |
( |
String |
groupID, |
|
|
final V2TIMCallback |
callback |
|
) |
| |
|
abstract |
4.7 Delete a group
- Attention
- Note the following special logic:
- For a work group (Work), even the group owner does not have the privilege to delete the group. To delete the group, you must have your service server to call the RESTful API Deleting a Group to delete the group.
- For other group types, the group owner can delete the group.
◆ getUsersInfo()
5.1 Get user profiles
- Attention
- Notes:
- To get your own profile, pass in your user ID.
- You are advised to specify no more than 100 user IDs in userIDList at a time. A larger number may cause the request to be rejected by the backend due to an excessively large data packet. The maximum size of a data packet supported by the backend is 1 MB.
◆ setSelfInfo()
5.2 Modify one's own user profile
◆ getUserStatus()
5.3 Get user status information(supported only in 6.3 and later versions)
- Parameters
-
userIDList | List of identifier of the users whose information is to be obtained. |
- Attention
- :
- Passed yourself id to @userIDList, your custom status would be returned.
- Only when all user's status obtained fail, @onError would be invoke.
◆ setSelfStatus()
5.4 Setup user status for yourself (supported only in 6.3 and later versions)
- Attention
- Only the customStatus field of V2TIMUserStatus can be set for yourself.
◆ subscribeUserStatus()
abstract void subscribeUserStatus |
( |
List< String > |
userIDList, |
|
|
V2TIMCallback |
callback |
|
) |
| |
|
abstract |
5.5 Subscribe user status (supported only in 6.3 and later versions)
- Parameters
-
userIDList | Identifiers for users whose status will be subscribed. |
- Attention
- :
- You will receive the status change notification by implement the onUserStatusChanged callback after succeffully subscribe user status.
- You can subscribe status of your friends by open the switch at console without call this API.
- Status subscription of yourself is not supported. You can implement the onUserStatusChanged callback to obtain the status change notification for yourself which has been set on other devices.
- There is a limit on the number of subscription list. The older subscriber will be automatically eliminated after exceeding the limit.
◆ unsubscribeUserStatus()
abstract void unsubscribeUserStatus |
( |
List< String > |
userIDList, |
|
|
V2TIMCallback |
callback |
|
) |
| |
|
abstract |
5.6 Unsubscribe user status (supported only in 6.3 and later versions)
- Parameters
-
userIDList | Identifiers for users whose status will be unsubscribed. If useridList is empty, status of all users will be unsubscribed. |
◆ getMessageManager()
Advanced message feature entry
- Returns
- Advanced message management class instance
◆ getGroupManager()
Advanced group feature entry
- Returns
- Advanced group management class instance
◆ getConversationManager()
Conversation feature entry
- Returns
- Conversation management class instance
◆ getFriendshipManager()
Relationship chain feature entry
- Returns
- Relationship chain management class instance
◆ getOfflinePushManager()
Offline push feature entry
- Returns
- Offline push feature class instance
◆ getSignalingManager()
Signaling entry
- Returns
- Signaling management class instance
◆ callExperimentalAPI()
abstract void callExperimentalAPI |
( |
String |
api, |
|
|
Object |
param, |
|
|
V2TIMValueCallback< Object > |
callback |
|
) |
| |
|
abstract |
Experimental API
- Parameters
-
api | API name |
param | API parameter |
- Attention
- This API provides some experimental features.
◆ V2TIM_STATUS_LOGINED
final int V2TIM_STATUS_LOGINED = 1 |
|
static |
Logged in
◆ V2TIM_STATUS_LOGINING
final int V2TIM_STATUS_LOGINING = 2 |
|
static |
Logging in
◆ V2TIM_STATUS_LOGOUT
final int V2TIM_STATUS_LOGOUT = 3 |
|
static |
Logged out
◆ GROUP_TYPE_WORK
final String GROUP_TYPE_WORK = "Work" |
|
static |
Work group
◆ GROUP_TYPE_PUBLIC
final String GROUP_TYPE_PUBLIC = "Public" |
|
static |
Public group
◆ GROUP_TYPE_MEETING
final String GROUP_TYPE_MEETING = "Meeting" |
|
static |
Meeting group
◆ GROUP_TYPE_AVCHATROOM
final String GROUP_TYPE_AVCHATROOM = "AVChatRoom" |
|
static |
Audio-video group
◆ GROUP_TYPE_COMMUNITY
final String GROUP_TYPE_COMMUNITY = "Community" |
|
static |
Community