IMSDK
IM features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication. It also provides complete app access and backend management APIs.
V2TIMManagerabstract

Detailed Description

Core class of the Chat SDK, implementing features such as Chat SDK initialization and login, message sending and receiving, and group creation and quitting

Public Member Functions

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 subscribeUserInfo (List< String > userIDList, V2TIMCallback callback)
 
abstract void unsubscribeUserInfo (List< String > userIDList, 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)
 

Static Public Member Functions

static V2TIMManager getInstance ()
 
static V2TIMMessageManager getMessageManager ()
 
static V2TIMGroupManager getGroupManager ()
 
static V2TIMCommunityManager getCommunityManager ()
 
static V2TIMConversationManager getConversationManager ()
 
static V2TIMFriendshipManager getFriendshipManager ()
 
static V2TIMOfflinePushManager getOfflinePushManager ()
 
static V2TIMSignalingManager getSignalingManager ()
 

Static Public Attributes

static final int V2TIM_STATUS_LOGINED = 1
 
static final int V2TIM_STATUS_LOGINING = 2
 
static final int V2TIM_STATUS_LOGOUT = 3
 
static final String GROUP_TYPE_WORK = "Work"
 
static final String GROUP_TYPE_PUBLIC = "Public"
 
static final String GROUP_TYPE_MEETING = "Meeting"
 
static final String GROUP_TYPE_AVCHATROOM = "AVChatRoom"
 
static final String GROUP_TYPE_COMMUNITY = "Community"
 

Member Function Documentation

◆ getInstance()

static V2TIMManager getInstance ( )
inlinestatic

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
contextContext
sdkAppIDApp ID. This field is required. You can obtain the app ID from the console.
configConfiguration information
Returns
true: successful; false: failed. If context is empty, false is returned.

◆ unInitSDK()

abstract void unInitSDK ( )
abstract

1.3 Uninitialize the SDK

◆ addIMSDKListener()

abstract void addIMSDKListener ( V2TIMSDKListener  listener)
abstract

1.4 Add a Chat listener

◆ removeIMSDKListener()

abstract void removeIMSDKListener ( V2TIMSDKListener  listener)
abstract

1.5 Remove a Chat listener

◆ 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
UTC timestamp, in seconds

◆ initSDK() [2/2]

abstract boolean initSDK ( Context  context,
int  sdkAppID,
V2TIMSDKConfig  config,
V2TIMSDKListener  listener 
)
abstract

1.8 Initialize the SDK

Parameters
contextContext
sdkAppIDApp ID. This field is required. You can obtain the app ID from the console.
configConfiguration information
listenerSDK 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 Log in

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 V2TIMListener -> onUserSigExpired callback may also be triggered when the user is online. In this case, generate a new userSig and log in again.
  • An online user is kicked offline: this will be notified by the V2TIMListener -> onKickedOffline callback. After receiving this callback, you can notify the user via the UI and call login() to log the user in again.

◆ logout()

abstract void logout ( V2TIMCallback  callback)
abstract

2.2 Log out

In the case of switching accounts, after the user logs out, they can log in again only after a logout callback is received (whether the logout succeeds or fails).

◆ getLoginUser()

abstract String getLoginUser ( )
abstract

2.3 Get the logged in user

◆ 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()

abstract void addSimpleMsgListener ( V2TIMSimpleMsgListener  v2TIMSimpleMsgListener)
abstract

3.1 Set the event listener for simple messages (text messages and custom messages)

Attention
For the event listener for advanced messages such as image, video, and voice messages, please see V2TIMMessageManager.addAdvancedMsgListener(V2TIMAdvancedMsgListener).

◆ removeSimpleMsgListener()

abstract void removeSimpleMsgListener ( V2TIMSimpleMsgListener  v2TIMSimpleMsgListener)
abstract

3.2 Remove the event listener for simple messages (text messages and custom messages)

◆ sendC2CTextMessage()

abstract String sendC2CTextMessage ( String  text,
String  userID,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

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()

abstract String sendC2CCustomMessage ( byte []  customData,
String  userID,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

3.4 Send a one-to-one custom (signaling) message (up to 12 KB)

A custom message is essentially a binary buffer which allows you to customize your message format (often used to send signaling). 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()

abstract String sendGroupTextMessage ( String  text,
String  groupID,
int  priority,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

3.5 Send a group text message (up to 12 KB)

Parameters
priorityMessage priority. There is no guarantee that each message will reach all users, but higher-priority messages will have a higher delivery success rate.
  • V2TIMMessage.V2TIM_PRIORITY_HIGH: the message will be transferred with a high priority on the cloud. This setting is suitable for sending important messages in a group, such as text messages sent by the host.
  • V2TIMMessage.V2TIM_PRIORITY_NORMAL: the message will be transferred with the default priority on the cloud. This setting is suitable for sending less important messages in a 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()

abstract String sendGroupCustomMessage ( byte []  customData,
String  groupID,
int  priority,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

3.6 Send a group custom (signaling) message (up to 12 KB)

Parameters
priorityMessage priority. There is no guarantee that each message will reach all users, but higher-priority messages will have a higher delivery success rate.
  • V2TIMMessage.V2TIM_PRIORITY_HIGH: the message will be transferred with a high priority on the cloud. This setting is suitable for sending important messages in a 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 less important signaling in a group, such as likes given by the audience.
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()

abstract void setGroupListener ( V2TIMGroupListener  listener)
abstract

4.1 Set the group listener

◆ addGroupListener()

abstract void addGroupListener ( V2TIMGroupListener  listener)
abstract

4.2 Add the group listener

◆ removeGroupListener()

abstract void removeGroupListener ( V2TIMGroupListener  listener)
abstract

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
groupTypeGroup type. The following group types are preset in the SDK. You can also customize group types in the console:
  • Work group (Work): supports up to 200 members; allows join by invitation only; suitable for work groups like those in WeCom (corresponding to Private groups in earlier versions)
  • 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 earlier versions)
  • 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 Premium 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
groupIDCustom group ID. "null" can be passed in. When "null" is passed in, the system automatically assigns a group ID and returns it via a callback. Custom group ID of "Community" must start with "@TGS#_".
groupNameGroup name. The value cannot be "null". The maximum length is 100 bytes, using UTF-8 encoding, and 1 Chinese character occupies 3 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 the user is logged in again, for them to continue to receive messages from the same Audio-video group, please call joinGroup to join the group again.

◆ 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 the user is logged in again, for them to continue to receive messages from the same Audio-video group, please call joinGroup to join the group again.

◆ 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 call the RESTful API Deleting a Group.
  • For other group types, the group owner can delete the group.

◆ getUsersInfo()

abstract void getUsersInfo ( List< String >  userIDList,
V2TIMValueCallback< List< V2TIMUserFullInfo >>  callback 
)
abstract

5.1 Get user profiles

Attention
  • 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()

abstract void setSelfInfo ( V2TIMUserFullInfo  info,
V2TIMCallback  callback 
)
abstract

5.2 Modify one's own user profile

◆ subscribeUserInfo()

abstract void subscribeUserInfo ( List< String >  userIDList,
V2TIMCallback  callback 
)
abstract

5.3 Subscribe to user profiles (supported only in Chat Premium 7.4 and later versions)

Parameters
userIDList
Attention
  • This API is used to subscribe to stranger profiles, and after successfully subscribing, you will receive profile change notifications via the onUserInfoChanged callback.
  • A maximum of 200 subscriptions are allowed. When the limit is exceeded, the earliest subscriptions will be automatically eliminated.
  • You don't need to subscribe to your own or your friends' profiles. By default, any changes to your own and your friends' profiles will be notified via the onSelfInfoUpdated and onFriendInfoChange callback.

◆ unsubscribeUserInfo()

abstract void unsubscribeUserInfo ( List< String >  userIDList,
V2TIMCallback  callback 
)
abstract

5.4 Unsubscribe user profile (supported only in Chat Premium 7.4 and later versions)

Parameters
userIDListIdentifiers for users whose profiles you want to unsubscribe from. If userIDList is empty, all subscriptions will be canceled.

◆ getUserStatus()

abstract void getUserStatus ( List< String >  userIDList,
V2TIMValueCallback< List< V2TIMUserStatus >>  callback 
)
abstract

5.5 Get user status information (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListList of identifier of the users whose information is to be obtained.
Attention
  • To get your own custom status, pass in your userID.
  • An error will be returned only if query fails for all specified users.

◆ setSelfStatus()

abstract void setSelfStatus ( V2TIMUserStatus  status,
V2TIMCallback  callback 
)
abstract

5.6 Set your own user status (supported only in 6.3 and later versions)

Attention
You can only set your custom status (the customStatus field of V2TIMUserStatus) using this API.

◆ subscribeUserStatus()

abstract void subscribeUserStatus ( List< String >  userIDList,
V2TIMCallback  callback 
)
abstract

5.7 Subscribe to user status (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListIdentifiers for users whose status you want to subscribe to.
Attention
  • You will receive status change notifications via the onUserStatusChanged callback after successfully subscribing to user status.
  • To subscribe to the status of your friends, instead of calling this API, please configure it in the console.
  • You cannot use this API to subscribe to your own status. Instead, you can receive notifications about change of your own custom status via the onUserStatusChanged callback.
  • A maximum of 200 subscriptions are allowed. When the limit is exceeded, earlier subscriptions will be automatically canceled.

◆ unsubscribeUserStatus()

abstract void unsubscribeUserStatus ( List< String >  userIDList,
V2TIMCallback  callback 
)
abstract

5.8 Unsubscribe from user status (supported only in Chat Premium 6.3 and later versions)

Parameters
userIDListIdentifiers for users whose status you want to unsubscribe from. If useridList is empty, all subscriptions will be canceled.

◆ getMessageManager()

static V2TIMMessageManager getMessageManager ( )
inlinestatic

Advanced message feature entry

Returns
Advanced message management class instance

◆ getGroupManager()

static V2TIMGroupManager getGroupManager ( )
inlinestatic

Advanced group feature entry

Returns
Advanced group management class instance

◆ getCommunityManager()

static V2TIMCommunityManager getCommunityManager ( )
inlinestatic

Community feature entry

Returns
Community management class instance

◆ getConversationManager()

static V2TIMConversationManager getConversationManager ( )
inlinestatic

Conversation feature entry

Returns
Conversation management class instance

◆ getFriendshipManager()

static V2TIMFriendshipManager getFriendshipManager ( )
inlinestatic

Relationship chain feature entry

Returns
Relationship chain management class instance

◆ getOfflinePushManager()

static V2TIMOfflinePushManager getOfflinePushManager ( )
inlinestatic

Offline push feature entry

Returns
Offline push feature class instance

◆ getSignalingManager()

static V2TIMSignalingManager getSignalingManager ( )
inlinestatic

Signaling entry

Returns
Signaling management class instance

◆ callExperimentalAPI()

abstract void callExperimentalAPI ( String  api,
Object  param,
V2TIMValueCallback< Object >  callback 
)
abstract

Experimental API

Parameters
apiAPI name
paramAPI parameter
Attention
This API provides some experimental features.

Field Documentation

◆ 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