Event Listener
The Android SDK provides interfaces to listen to various events on the client app. Through these interfaces, TapTalk.io notifies the client app of events that happen on your app.
TapTalk.io provides six types of event listeners to notify events to the client app. You will need to register the listener objects to receive event callbacks from TapTalk.io.
Event Listener
Description
Listens to general event changes in the application
Listens to UI-related events in Room List View when UI implementation type is used
Listens to UI-related events in Chat Room View when UI implementation type is used
Listens to UI-related events in Chat Profile View when UI implementation type is used
Listens to custom keyboard-related events when UI implementation type is used
Listens to events when a new/updated message is received by the application
Listens to room status events such as typing events and online status

TapListener

General events such as notifications will be notified through TapListener. A TapListener instance is required when initializing TapTalk.
Java
Kotlin
1
TapListener tapListener = new TapListener() {
2
@Override
3
public void onInitializationCompleted(String instanceKey) {
4
// Initialization process has finished
5
}
6
7
@Override
8
public void onTapTalkRefreshTokenExpired() {
9
// Authentication is needed
10
}
11
12
@Override
13
public void onTapTalkUnreadChatRoomBadgeCountUpdated(int unreadCount) {
14
// Returns number of unread messages from the application
15
}
16
17
@Override
18
public void onNotificationReceived(TAPMessageModel message) {
19
// A new message from TapTalk.io is received
20
}
21
22
@Override
23
public void onUserLogout() {
24
// User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed
25
}
26
27
@Override
28
public void onTaskRootChatRoomClosed(Activity activity) {
29
// A chat room activity was closed by user when no other activity in the application is present
30
}
31
};
32
33
TapTalk.init(
34
CONTEXT,
35
APP_KEY_ID,
36
APP_KEY_SECRET,
37
APP_ICON,
38
APP_NAME,
39
APP_BASE_URL,
40
IMPLEMENTATION_TYPE,
41
tapListener);
Copied!
1
var tapListener: TapListener = object : TapListener() {
2
override fun onInitializationCompleted(instanceKey: String) {
3
// Initialization process has finished
4
}
5
6
override fun onTapTalkRefreshTokenExpired() {
7
// Authentication is needed
8
}
9
10
override fun onTapTalkUnreadChatRoomBadgeCountUpdated(unreadCount: Int) {
11
// Returns number of unread messages from the application
12
}
13
14
override fun onNotificationReceived(message: TAPMessageModel?) {
15
// A new message from TapTalk.io is received
16
}
17
18
override fun onUserLogout() {
19
// User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed
20
}
21
22
override fun onTaskRootChatRoomClosed(activity: Activity?) {
23
// A chat room activity was closed by user when no other activity in the application is present
24
}
25
}
26
27
TapTalk.init(
28
CONTEXT,
29
APP_KEY_ID,
30
APP_KEY_SECRET,
31
APP_ICON,
32
APP_NAME,
33
APP_BASE_URL,
34
IMPLEMENTATION_TYPE,
35
tapListener)
Copied!
TapListener listens to changes in the following methods:
Method Name
Invoked When
onInitializationCompleted()
TapTalk instance has finished initialization process.
onTapTalkRefreshTokenExpired()
User's refresh token has expired. An authentication with a new auth ticket is required.
onTapTalkUnreadChatRoomBadgeCountUpdated()
The number of unread messages in the application is updated. Returns the number of unread messages from the application.
onNotificationReceived()
User receives new message from TapTalk.io through notification. Returns the newly received message.
onUserLogout()
User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed
onTaskRootChatRoomClosed
A chat room activity was closed by user when no other activity in the application is present (application will close).

TapUIRoomListListener

TapUIRoomListListener listens to UI-related events in Room List View when UI implementation type is used. You can register a TapUIRoomListListener instance in your application through the TapUI class as follows:
Java
Kotlin
1
TapUI.getInstance().addRoomListListener(new TapUIRoomListListener() {
2
@Override
3
public void onSearchChatBarTapped(Activity activity, TapUIMainRoomListFragment mainRoomListFragment) {
4
// Calling super will open search chat page by default
5
super.onSearchChatBarTapped(activity, mainRoomListFragment);
6
}
7
8
@Override
9
public void onCloseRoomListTapped(Activity activity) {
10
// Calling super will close TapTalk's room list activity by default
11
super.onCloseRoomListTapped(activity);
12
}
13
14
@Override
15
public void onTapTalkAccountButtonTapped(Activity activity) {
16
// Calling super will open TapTalk user account page by default
17
super.onTapTalkAccountButtonTapped(activity);
18
}
19
20
@Override
21
public void onNewChatButtonTapped(Activity activity) {
22
// Calling super will open TapTalk start new chat page by default
23
super.onNewChatButtonTapped(activity);
24
}
25
});
Copied!
1
TapUI.getInstance().addRoomListListener(object : TapUIRoomListListener() {
2
override fun onSearchChatBarTapped(activity: Activity, mainRoomListFragment: TapUIMainRoomListFragment) {
3
// Calling super will open search chat page by default
4
super.onSearchChatBarTapped(activity, mainRoomListFragment)
5
}
6
7
override fun onCloseRoomListTapped(activity: Activity) {
8
// Calling super will close TapTalk's room list activity by default
9
super.onCloseRoomListTapped(activity)
10
}
11
12
override fun onTapTalkAccountButtonTapped(activity: Activity) {
13
// Calling super will open TapTalk user account page by default
14
super.onTapTalkAccountButtonTapped(activity)
15
}
16
17
override fun onNewChatButtonTapped(activity: Activity) {
18
// Calling super will open TapTalk start new chat page by default
19
super.onNewChatButtonTapped(activity)
20
}
21
22
23
})
Copied!
Method Name
Invoked When
onSearchBarTapped()
Search bar in room list is tapped by active user. Returns the room list activity instance and TapUIMainRoomListFragment instance.
onCloseRoomListTapped()
TapTalk's room list activity is closed by active user. Returns the room list activity instance.
onTapTalkAccountButtonTapped()
My account button in top right room list view is tapped by active user. Returns the room list activity instance.
onNewChatButtonTapped()
Floating New Chat button on the bottom right of the room list view is tapped by active user. Returns the room list activity instance.

TapUIChatRoomListener

TapUIChatRoomListener listens to UI-related events in Chat Room View when UI implementation type is used. You can register a TapUIChatRoomListener instance in your application through the TapUI class as follows:
Java
Kotlin
1
TapUI.getInstance().addChatRoomListener(new TapUIChatRoomListener() {
2
@Override
3
public void onTapTalkChatRoomOpened(Activity activity, TAPRoomModel room, @Nullable TAPUserModel otherUser) {
4
// Returns activity instance and opened room model
5
}
6
7
@Override
8
public void onTapTalkChatRoomClosed(Activity activity, TAPRoomModel room, @Nullable TAPUserModel otherUser) {
9
// Returns activity instance and closed room model
10
}
11
@Override
12
public void onTapTalkActiveUserSendMessage(Activity activity, TAPMessageModel messageModel, TAPRoomModel room) {
13
// Returns activity instance, temporary message model to be sent, and the room where the message is being sent
14
}
15
16
@Override
17
public void onTapTalkUserProfileButtonTapped(Activity activity, TAPRoomModel room, TAPUserModel user) {
18
// Using super will open TapTalk user profile by default
19
super.onTapTalkUserProfileButtonTapped(activity, room, user);
20
}
21
22
@Override
23
public void onTapTalkGroupChatProfileButtonTapped(Activity activity, TAPRoomModel room) {
24
// Using super will open TapTalk group chat profile by default
25
super.onTapTalkGroupChatProfileButtonTapped(activity, room);
26
}
27
28
@Override
29
public void onTapTalkGroupMemberAvatarTapped(Activity activity, TAPRoomModel room, TAPUserModel user) {
30
// Using super will open TapTalk user profile by default
31
super.onTapTalkGroupMemberAvatarTapped(activity, room, user);
32
}
33
34
@Override
35
public void onTapTalkUserMentionTapped(Activity activity, TAPMessageModel messageModel, TAPUserModel user, boolean isRoomParticipant) {
36
// Using super will open TapTalk user profile by default
37
super.onTapTalkUserMentionTapped(activity, messageModel, user, isRoomParticipant);
38
}
39
40
@Override
41
public void onTapTalkMessageQuoteTapped(Activity activity, TAPMessageModel message, HashMap<String, Object> userInfo) {
42
// Returns activity instance, tapped message, and userInfo
43
}
44
});
Copied!
1
TapUI.getInstance().addChatRoomListener(object : TapUIChatRoomListener() {
2
override fun onTapTalkChatRoomOpened(activity: Activity, room: TAPRoomModel, otherUser: TAPUserModel?) {
3
// Returns activity instance and opened room model
4
}
5
6
override fun onTapTalkChatRoomClosed(activity: Activity, room: TAPRoomModel, otherUser: TAPUserModel?) {
7
// Returns activity instance and closed room model
8
}
9
10
override fun onTapTalkActiveUserSendMessage(activity: Activity, messageModel: TAPMessageModel, room: TAPRoomModel) {
11
// Returns activity instance, temporary message model to be sent, and the destination room
12
}
13
14
override fun onTapTalkUserProfileButtonTapped(activity: Activity, room: TAPRoomModel, user: TAPUserModel?) {
15
// Using super will open TapTalk user profile by default
16
super.onTapTalkUserProfileButtonTapped(activity, room, user)
17
}
18
19
override fun onTapTalkGroupChatProfileButtonTapped(activity: Activity, room: TAPRoomModel) {
20
// Using super will open TapTalk group chat profile by default
21
super.onTapTalkGroupChatProfileButtonTapped(activity, room)
22
}
23
24
override fun onTapTalkGroupMemberAvatarTapped(activity: Activity, room: TAPRoomModel, user: TAPUserModel) {
25
// Using super will open TapTalk user profile by default
26
super.onTapTalkGroupMemberAvatarTapped(activity, room, user)
27
}
28
29
override fun onTapTalkUserMentionTapped(activity: Activity, messageModel: TAPMessageModel, user: TAPUserModel, isRoomParticipant: Boolean) {
30
// Using super will open TapTalk user profile by default
31
super.onTapTalkUserMentionTapped(activity, messageModel, user, isRoomParticipant)
32
}
33
34
override fun onTapTalkMessageQuoteTapped(activity: Activity, message: TAPMessageModel, userInfo: HashMap<String, Any>?) {
35
// Returns activity instance, tapped message, and userInfo
36
}
37
})
Copied!
Method Name
Invoked When
onTapTalkChatRoomOpened()
A chat room is opened. Returns the opened activity instance and room model.
onTapTalkChatRoomClosed()
A chat room is closed. Returns the closed activity instance and room model.
onTapTalkActiveUserSendMessage()
Active user sends any message to a chat room. Message may not yet be delivered to the room when this happens. Returns the activity instance, message to be sent, and the destination room. Returned message is temporary and the values will be updated through socket once the message is delivered.
onTapTalkUserProfileButtonTapped()
Profile button in a personal chat room is tapped by active user. Returns the activity instance, room, and recipient user.
onTapTalkGroupChatProfileButtonTapped()
Profile button in a group chat room is tapped by active user. Returns the activity instance and room.
onTapTalkGroupMemberAvatarTapped()
A group member's profile picture on a message bubble in group chat room is tapped by active user. Returns the activity instance, room, and recipient user.
onTapTalkUserMentionTapped()
A user mention span in a chat bubble is tapped by active user. Returns activity instance, message model, mentioned user model, and isRoomParticipant
onTapTalkMessageQuoteTapped()
A quote inside a message bubble in a chat room is tapped by active user. Returns activity instance, tapped message, and userInfo. UserInfo is a HashMap object embedded inside a message containing data specified by client, and is generally null when not specified.

TapUIChatProfileListener

TapUIChatProfileListener listens to UI-related events in Chat Profile View when UI implementation type is used. You can register a TapUIChatProfileListener instance in your application through the TapUI class as follows:
Java
Kotlin
1
TapUI.getInstance().addChatProfileListener(new TapUIChatProfileListener() {
2
@Override
3
public void onReportUserButtonTapped(Activity activity, TAPRoomModel room, TAPUserModel reportedUser) {
4
// Returns activity instance, room model, and user model
5
}
6
7
@Override
8
public void onReportGroupButtonTapped(Activity activity, TAPRoomModel room) {
9
// Returns activity instance and room model
10
}
11
});
Copied!
1
TapUI.getInstance().addChatProfileListener(object : TapUIChatProfileListener() {
2
override fun onReportUserButtonTapped(activity: Activity, room: TAPRoomModel, reportedUser: TAPUserModel) {
3
// Returns activity instance, room model, and user model
4
}
5
6
override fun onReportGroupButtonTapped(activity: Activity, room: TAPRoomModel) {
7
// Returns activity instance and room model
8
}
9
})
Copied!
Method Name
Invoked When
onReportUserButtonTapped()
Active user taps the Report User button in chat profile view. Returns activity instance, room model, and the reported user model.
onReportGroupButtonTapped()
Active user taps the Report Group button in chat profile view. Returns activity instance and room model.

TapCustomKeyboardListener

TapCustomKeyboardListener bridges the custom keyboard-related events between TapTalk.io and the client app when UI implementation type is used. TapTalk.io will request custom keyboard items from the client app through this listener when a chat room is opened by the user. TapCustomKeyboardListener can be implemented using the TapUI class.
Java
Kotlin
1
TapUI.getInstance().addCustomKeyboardListener(new TapCustomKeyboardListener() {
2
@Override
3
public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
4
// Return items here if you wish to use custom keyboard in chat room
5
return null;
6
}
7
8
@Override
9
public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
10
// Do an action when user taps a custom keyboard item
11
}
12
});
Copied!
1
TapUI.getInstance().addCustomKeyboardListener(object : TapCustomKeyboardListener() {
2
override fun setCustomKeyboardItems(
3
room: TAPRoomModel?,
4
activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel?
5
): List<TAPCustomKeyboardItemModel>? {
6
// Return items here if you wish to use custom keyboard in chat room
7
return null
8
}
9
10
override fun onCustomKeyboardItemTapped(
11
activity: Activity?,
12
customKeyboardItem: TAPCustomKeyboardItemModel?,
13
room: TAPRoomModel?,
14
activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel?
15
) {
16
// Do an action when user taps a custom keyboard item
17
}
18
})
Copied!
To use custom keyboard in the chat room, return a list of TAPCustomKeyboardItemModel on the setCustomKeyboardItems() method in this listener. See the example below:JavaKotlin
Java
Kotlin
1
TapCustomKeyboardManager.getInstance().addCustomKeyboardListener(new TapCustomKeyboardListener() {
2
@Override
3
public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
4
List<TAPCustomKeyboardItemModel> customKeyboardItems = new ArrayList<>();
5
TAPCustomKeyboardItemModel customKeyboardItem1 = new TAPCustomKeyboardItemModel(
6
"customKeyboardItem1",
7
getDrawable(R.drawable.keyboard_icon_1),
8
"Hello, " + room.getRoomName()
9
);
10
TAPCustomKeyboardItemModel customKeyboardItem2 = new TAPCustomKeyboardItemModel(
11
"customKeyboardItem2",
12
"https://www.yoururl.com/image2.png",
13
"Hello, my name is " + activeUser.getName()
14
);
15
customKeyboardItems.add(customKeyboardItem1);
16
customKeyboardItems.add(customKeyboardItem2);
17
return customKeyboardItems;
18
}
19
20
@Override
21
public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
22
if (customKeyboardItem.getItemID().equals("customKeyboardItem1")) {
23
// Custom keyboard item 1 was tapped by user
24
} else if (customKeyboardItem.getItemID().equals("customKeyboardItem2")) {
25
// Custom keyboard item 2 was tapped by user
26
}
27
}
28
});
Copied!
1
TapCustomKeyboardManager.getInstance().addCustomKeyboardListener(object : TapCustomKeyboardListener() {
2
override fun setCustomKeyboardItems(
3
room: TAPRoomModel?,
4
activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel?
5
): List<TAPCustomKeyboardItemModel> {
6
val customKeyboardItems = ArrayList()
7
val customKeyboardItem1 = TAPCustomKeyboardItemModel(
8
"customKeyboardItem1",
9
getDrawable(R.drawable.keyboard_icon_1),
10
"Hello, " + room.getRoomName()
11
)
12
val customKeyboardItem2 = TAPCustomKeyboardItemModel(
13
"customKeyboardItem2",
14
"https://www.yoururl.com/image2.png",
15
"Hello, my name is " + activeUser!!.name
16
)
17
customKeyboardItems.add(customKeyboardItem1)
18
customKeyboardItems.add(customKeyboardItem2)
19
return customKeyboardItems
20
}
21
22
override fun onCustomKeyboardItemTapped(
23
activity: Activity?,
24
customKeyboardItem: TAPCustomKeyboardItemModel?,
25
room: TAPRoomModel?,
26
activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel?
27
) {
28
if (customKeyboardItem!!.itemID == "customKeyboardItem1") {
29
// Custom keyboard item 1 was tapped by user
30
} else if (customKeyboardItem.itemID == "customKeyboardItem2") {
31
// Custom keyboard item 2 was tapped by user
32
}
33
}
34
})
Copied!
Method Name
Invoked When
setCustomKeyboardItems()
Chat room is opened. TapTalk.io will request custom keyboard items from the client app to be displayed in the chat room. Returns room, active user, and the recipient user (only for personal chat room)
onCustomKeyboardItemTapped()
A custom keyboard item in a chat room is tapped by the user. Returns the activity instance, custom keyboard item, room, active user, and recipient user (only for personal chat room)

TapCoreMessageListener

TapCoreMessageListener listens to message-related events, such as receiving new or updated message. TapCoreMessageListener can be registered through the TapCoreMessageManager class.JavaKotlin
Java
Kotlin
1
TapCoreMessageManager.getInstance().addMessageListener(new TapCoreMessageListener() {
2
@Override
3
public void onReceiveNewMessage(TAPMessageModel message) {
4
5
}
6
7
@Override
8
public void onReceiveUpdatedMessage(TAPMessageModel message) {
9
10
}
11
12
@Override
13
public void onMessageDeleted(TAPMessageModel message) {
14
15
}
16
17
@Override
18
public void onRequestMessageFileUpload(TAPMessageModel message, Uri fileUri) {
19
20
}
21
});
Copied!
1
TapCoreMessageManager.getInstance().addMessageListener(object : TapCoreReceiveMessageListener() {
2
override fun onReceiveNewMessage(message: TAPMessageModel?) {
3
4
}
5
6
override fun onReceiveUpdatedMessage(message: TAPMessageModel?) {
7
8
}
9
10
override fun onMessageDeleted(message: TAPMessageModel?) {
11
12
}
13
14
override fun onRequestMessageFileUpload(message: TAPMessageModel?, fileUri: Uri?) {
15
16
}
17
})
Copied!
Method Name
Invoked When
onReceiveNewMessage()
A new message is received. Returns the newly received message.
onReceiveUpdatedMessage()
An updated message is received. Returns the updated message.
onMessageDeleted()
A message is deleted. Returns the deleted message.
onRequestMessageFileUpload()
Active user sends a message with file, such as image, video, or document. Returns the message to be sent and the uri of the file to be uploaded by the client.
Note: the callback onRequestMessageFileUpload() will only be invoked when the user calls setUploadMessageFileToExternalServerEnabled(true) in TapCoreMessageManager. Enabling this will prevent the SDK from uploading message files, which are image, video, or document, to TapTalk servers, means the message will not be sent until the client returns the uploaded file's URL to the SDK through the onFileUploadCompleted method in TapCoreMessageManager.

TapCoreChatRoomListener

Room status events such as typing events and online status are notified through TapCoreChatRoomListener. An instance of TapCoreChatRoomListener can be registered from the TapCoreChatRoomManager class.
Java
Kotlin
1
TapCoreChatRoomManager.getInstance().addChatRoomListener(new TapCoreChatRoomListener() {
2
@Override
3
public void onReceiveStartTyping(String roomID, TAPUserModel user) {
4
5
}
6
7
@Override
8
public void onReceiveStopTyping(String roomID, TAPUserModel user) {
9
10
}
11
12
@Override
13
public void onReceiveOnlineStatus(TAPUserModel user, Boolean isOnline, Long lastActive) {
14
15
}
16
});
Copied!
1
TapCoreChatRoomManager.getInstance().addChatRoomListener(object : TapCoreChatRoomListener() {
2
override fun onReceiveStartTyping(roomID: String?, user: TAPUserModel?) {
3
4
}
5
6
override fun onReceiveStopTyping(roomID: String?, user: TAPUserModel?) {
7
8
}
9
10
override fun onReceiveOnlineStatus(
11
user: TAPUserModel?,
12
isOnline: Boolean?,
13
lastActive: Long?
14
) {
15
16
}
17
})
Copied!
Method Name
Invoked When
onReceiveStartTyping()
Another user starts typing a message in a chat room. Returns the room ID and typing user.
onReceiveStopTyping()
Another user stops typing a message in a chat room. Returns the room ID and typing user.
onReceiveOnlineStatus()
Another user comes online or offline. Returns the updated user, online status, and the updated user's last active time stamp.