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. You will need to register the listener objects to receive event callbacks from TapTalk.io.
Listens to contact related events such as block or unblock contact
TapListener
General events such as notifications will be notified through TapListener. A TapListener instance is required when initializing TapTalk.
We strongly suggest to override onTapTalkRefreshTokenExpired to handle authentication when the user's session has expired.
TapListener tapListener =newTapListener() { @OverridepublicvoidonInitializationCompleted(String instanceKey) {// Initialization process has finished } @OverridepublicvoidonTapTalkRefreshTokenExpired() {// Authentication is needed } @OverridepublicvoidonTapTalkUnreadChatRoomBadgeCountUpdated(int unreadCount) {// Returns number of unread messages from the application } @OverridepublicvoidonNotificationReceived(TAPMessageModel message) {// A new message from TapTalk.io is received } @OverridepublicvoidonUserLogout() {// User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed } @OverridepublicvoidonTaskRootChatRoomClosed(Activity activity) {// A chat room activity was closed by user when no other activity in the application is present// You may start another activity to keep the app open, otherwise the app will stay closed }};TapTalk.init( CONTEXT, APP_KEY_ID, APP_KEY_SECRET, APP_ICON, APP_NAME, APP_BASE_URL, IMPLEMENTATION_TYPE, tapListener);
var tapListener: TapListener=object : TapListener() {overridefunonInitializationCompleted(instanceKey: String) {// Initialization process has finished }overridefunonTapTalkRefreshTokenExpired() {// Authentication is needed }overridefunonTapTalkUnreadChatRoomBadgeCountUpdated(unreadCount: Int) {// Returns number of unread messages from the application }overridefunonNotificationReceived(message: TAPMessageModel?) {// A new message from TapTalk.io is received }overridefunonUserLogout() {// User has finished logging out from TapUI or TapTalk.logoutAndClearAllTapTalkData() process has completed }overridefunonTaskRootChatRoomClosed(activity: Activity?) {// A chat room activity was closed by user when no other activity in the application is present }}TapTalk.init( CONTEXT, APP_KEY_ID, APP_KEY_SECRET, APP_ICON, APP_NAME, APP_BASE_URL, IMPLEMENTATION_TYPE, tapListener)
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:
TapUI.getInstance().addRoomListListener(newTapUIRoomListListener() { @OverridepublicvoidonSearchChatBarTapped(Activity activity,TapUIMainRoomListFragment mainRoomListFragment) {// Calling super will open search chat page by default super.onSearchChatBarTapped(activity, mainRoomListFragment); } @OverridepublicvoidonCloseRoomListTapped(Activity activity) {// Calling super will close TapTalk's room list activity by default super.onCloseRoomListTapped(activity); } @OverridepublicvoidonTapTalkAccountButtonTapped(Activity activity) {// Calling super will open TapTalk user account page by default super.onTapTalkAccountButtonTapped(activity); } @OverridepublicvoidonNewChatButtonTapped(Activity activity) {// Calling super will open TapTalk start new chat page by default super.onNewChatButtonTapped(activity); }});
TapUI.getInstance().addRoomListListener(object : TapUIRoomListListener() {overridefunonSearchChatBarTapped(activity: Activity, mainRoomListFragment: TapUIMainRoomListFragment) {// Calling super will open search chat page by defaultsuper.onSearchChatBarTapped(activity, mainRoomListFragment) }overridefunonCloseRoomListTapped(activity: Activity) {// Calling super will close TapTalk's room list activity by defaultsuper.onCloseRoomListTapped(activity) }overridefunonTapTalkAccountButtonTapped(activity: Activity) {// Calling super will open TapTalk user account page by defaultsuper.onTapTalkAccountButtonTapped(activity) }overridefunonNewChatButtonTapped(activity: Activity) {// Calling super will open TapTalk start new chat page by defaultsuper.onNewChatButtonTapped(activity) }})
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.
Your are also able to customize existing long press menus through this listener.
You can register a TapUIChatRoomListener instance in your application through the TapUI class as follows:
TapUI.getInstance().addChatRoomListener(newTapUIChatRoomListener() { @OverridepublicvoidonTapTalkChatRoomOpened(Activity activity,TAPRoomModel room, @NullableTAPUserModel otherUser) {// Returns activity instance and opened room model } @OverridepublicvoidonTapTalkChatRoomClosed(Activity activity,TAPRoomModel room, @NullableTAPUserModel otherUser) {// Returns activity instance and closed room model } @OverridepublicvoidonTapTalkActiveUserSendMessage(Activity activity,TAPMessageModel messageModel,TAPRoomModel room) {// Returns activity instance, temporary message model to be sent, and the room where the message is being sent } @OverridepublicvoidonTapTalkUserProfileButtonTapped(Activity activity,TAPRoomModel room,TAPUserModel user) {// Using super will open TapTalk user profile by default super.onTapTalkUserProfileButtonTapped(activity, room, user); } @OverridepublicvoidonTapTalkGroupChatProfileButtonTapped(Activity activity,TAPRoomModel room) {// Using super will open TapTalk group chat profile by default super.onTapTalkGroupChatProfileButtonTapped(activity, room); } @OverridepublicvoidonTapTalkGroupMemberAvatarTapped(Activity activity,TAPRoomModel room,TAPUserModel user) {// Using super will open TapTalk user profile by default super.onTapTalkGroupMemberAvatarTapped(activity, room, user); } @Override public void onTapTalkUserMentionTapped(Activity activity, TAPMessageModel messageModel, TAPUserModel user, boolean isRoomParticipant) {
// Using super will open TapTalk user profile by default super.onTapTalkUserMentionTapped(activity, messageModel, user, isRoomParticipant); } @Override public void onTapTalkMessageQuoteTapped(Activity activity, TAPMessageModel message, HashMap<String, Object> userInfo) {
// Returns activity instance, tapped message, and userInfo } @OverridepublicList<TapLongPressMenuItem>setMessageLongPressMenuItems(Context context,TAPMessageModel messageModel) { // Return your customized list of TapLongPressMenuItem here if you wish to change the message's long press menu options
return super.setMessageLongPressMenuItems(context, messageModel); } @Override public List<TapLongPressMenuItem> setScheduledMessageLongPressMenuItems(Context context, TAPMessageModel messageModel) {
// Return your customized list of TapLongPressMenuItem here if you wish to change the scheduled message's long press menu options
return super.setScheduledMessageLongPressMenuItems(context, messageModel); } @Override public List<TapLongPressMenuItem> setLinkLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String url) {
// Return your customized list of TapLongPressMenuItem here if you wish to change the url's long press menu options
return super.setLinkLongPressMenuItems(context, messageModel, url); } @Override public List<TapLongPressMenuItem> setEmailLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String emailAddress) {
// Return your customized list of TapLongPressMenuItem here if you wish to change the email address's long press menu options
return super.setEmailLongPressMenuItems(context, messageModel, emailAddress); } @Override public List<TapLongPressMenuItem> setPhoneLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String phoneNumber) {
// Return your customized list of TapLongPressMenuItem here if you wish to change the phone number's long press menu options
return super.setPhoneLongPressMenuItems(context, messageModel, phoneNumber); } @Override public List<TapLongPressMenuItem> setMentionLongPressMenuItems(Context context, @Nullable TAPMessageModel messageModel, String mentionSpan) {
// Return your customized list of TapLongPressMenuItem here if you wish to change the mention's long press menu options
return super.setMentionLongPressMenuItems(context, messageModel, mentionSpan); } @Override public void onLongPressMenuItemSelected(Activity activity, TapLongPressMenuItem longPressMenuItem, TAPMessageModel messageModel) {
// A long press menu item was selected by user// You may add your own response and delete the super below super.onLongPressMenuItemSelected(activity, longPressMenuItem, messageModel); }});
TapUI.getInstance().addChatRoomListener(object : TapUIChatRoomListener() {overridefunonTapTalkChatRoomOpened(activity: Activity, room: TAPRoomModel, otherUser: TAPUserModel?) {// Returns activity instance and opened room model }overridefunonTapTalkChatRoomClosed(activity: Activity, room: TAPRoomModel, otherUser: TAPUserModel?) {// Returns activity instance and closed room model } override fun onTapTalkActiveUserSendMessage(activity: Activity, messageModel: TAPMessageModel, room: TAPRoomModel) {
// Returns activity instance, temporary message model to be sent, and the destination room }overridefunonTapTalkUserProfileButtonTapped(activity: Activity, room: TAPRoomModel, user: TAPUserModel?) {// Using super will open TapTalk user profile by defaultsuper.onTapTalkUserProfileButtonTapped(activity, room, user) }overridefunonTapTalkGroupChatProfileButtonTapped(activity: Activity, room: TAPRoomModel) {// Using super will open TapTalk group chat profile by defaultsuper.onTapTalkGroupChatProfileButtonTapped(activity, room) }overridefunonTapTalkGroupMemberAvatarTapped(activity: Activity, room: TAPRoomModel, user: TAPUserModel) {// Using super will open TapTalk user profile by defaultsuper.onTapTalkGroupMemberAvatarTapped(activity, room, user) } override fun onTapTalkUserMentionTapped(activity: Activity, messageModel: TAPMessageModel, user: TAPUserModel, isRoomParticipant: Boolean) {
// Using super will open TapTalk user profile by defaultsuper.onTapTalkUserMentionTapped(activity, messageModel, user, isRoomParticipant) } override fun onTapTalkMessageQuoteTapped(activity: Activity, message: TAPMessageModel, userInfo: HashMap<String, Any>?) {
// Returns activity instance, tapped message, and userInfo } override fun setMessageLongPressMenuItems(context: Context, messageModel: TAPMessageModel): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the message's long press menu options
returnsuper.setMessageLongPressMenuItems(context, messageModel) } override fun setScheduledMessageLongPressMenuItems(context: Context, messageModel: TAPMessageModel): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the scheduled message's long press menu options
returnsuper.setScheduledMessageLongPressMenuItems(context, messageModel) } override fun setLinkLongPressMenuItems(context: Context, messageModel: TAPMessageModel?, url: String): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the url's long press menu options
returnsuper.setLinkLongPressMenuItems(context, messageModel, url) } override fun setEmailLongPressMenuItems(context: Context, messageModel: TAPMessageModel?, emailAddress: String): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the email address's long press menu options
returnsuper.setEmailLongPressMenuItems(context, messageModel, emailAddress) } override fun setPhoneLongPressMenuItems(context: Context, messageModel: TAPMessageModel?, phoneNumber: String): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the phone number's long press menu options
returnsuper.setPhoneLongPressMenuItems(context, messageModel, phoneNumber) } override fun setMentionLongPressMenuItems(context: Context, messageModel: TAPMessageModel?, mentionSpan: String): List<TapLongPressMenuItem> {
// Return your customized list of TapLongPressMenuItem here if you wish to change the mention's long press menu options
returnsuper.setMentionLongPressMenuItems(context, messageModel, mentionSpan) } override fun onLongPressMenuItemSelected(activity: Activity, longPressMenuItem: TapLongPressMenuItem, messageModel: TAPMessageModel?) {
// A long press menu item was selected by user// You may add your own response and delete the super belowsuper.onLongPressMenuItemSelected(activity, longPressMenuItem, messageModel) }})
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.
setMessageLongPressMenuItems()
A message bubble in chat room is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context and the long pressed message.
setScheduledMessageLongPressMenuItems()
A message bubble in scheduled messages chat room is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context and the long pressed message.
setLinkLongPressMenuItems()
A URL inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the URL.
setEmailLongPressMenuItems()
An email address inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the email address.
setPhoneLongPressMenuItems()
A phone number inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the phone number.
setMentionLongPressMenuItems()
A mention span inside a message bubble is long pressed by user. TapTalk.io will request custom long press items from the client app to be displayed. Returns context, the long pressed message, and the mention span.
onLongPressMenuItemSelected()
A long press menu is selected by the active user. Returns the current activity, long pressed menu item, and the message model.
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:
TapUI.getInstance().addChatProfileListener(newTapUIChatProfileListener() { @OverridepublicvoidonReportUserButtonTapped(Activity activity,TAPRoomModel room,TAPUserModel reportedUser) {// Returns activity instance, room model, and user model } @OverridepublicvoidonReportGroupButtonTapped(Activity activity,TAPRoomModel room) {// Returns activity instance and room model } @OverridepublicvoidonGroupInCommonItemTapped(Activity activity,TAPRoomModel room) {// Returns activity instance and room model }});
TapUI.getInstance().addChatProfileListener(object : TapUIChatProfileListener() {overridefunonReportUserButtonTapped(activity: Activity, room: TAPRoomModel, reportedUser: TAPUserModel) {// Returns activity instance, room model, and user model }overridefunonReportGroupButtonTapped(activity: Activity, room: TAPRoomModel) {// Returns activity instance and room model }overridefunonGroupInCommonItemTapped(activity: Activity, room: TAPRoomModel) {// Returns activity instance and room model }})
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.
onGroupInCommonItemTapped()
Active user taps an item in Groups in Common list. Returns activity instance and room model.
TapUIMyAccountListener
TapUIMyAccountListener listens to UI-related events in My Account View when UI implementation type is used. You can register a TapUIMyAccountListener instance in your application through the TapUI class as follows:
Active user taps the Delete Account button in My Account view. Returns the currently active My Account activity instance.
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.
TapUI.getInstance().addCustomKeyboardListener(newTapCustomKeyboardListener() { @Override public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
// Return items here if you wish to use custom keyboard in chat roomreturnnull; } @Override public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
// Do an action when user taps a custom keyboard item }});
TapUI.getInstance().addCustomKeyboardListener(object : TapCustomKeyboardListener() {overridefunsetCustomKeyboardItems( room: TAPRoomModel?, activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel? ): List<TAPCustomKeyboardItemModel>? {// Return items here if you wish to use custom keyboard in chat roomreturnnull }overridefunonCustomKeyboardItemTapped( activity: Activity?, customKeyboardItem: TAPCustomKeyboardItemModel?, room: TAPRoomModel?, activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel? ) {// Do an action when user taps a custom keyboard item }})
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
TapCustomKeyboardManager.getInstance().addCustomKeyboardListener(newTapCustomKeyboardListener() { @Override public List<TAPCustomKeyboardItemModel> setCustomKeyboardItems(TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
List<TAPCustomKeyboardItemModel> customKeyboardItems =newArrayList<>();TAPCustomKeyboardItemModel customKeyboardItem1 =newTAPCustomKeyboardItemModel("customKeyboardItem1", getDrawable(R.drawable.keyboard_icon_1),"Hello, "+room.getRoomName() );TAPCustomKeyboardItemModel customKeyboardItem2 =newTAPCustomKeyboardItemModel("customKeyboardItem2","https://www.yoururl.com/image2.png","Hello, my name is "+activeUser.getName() ); customKeyboardItems.add(customKeyboardItem1); customKeyboardItems.add(customKeyboardItem2);return customKeyboardItems; } @Override public void onCustomKeyboardItemTapped(Activity activity, TAPCustomKeyboardItemModel customKeyboardItem, TAPRoomModel room, TAPUserModel activeUser, @Nullable TAPUserModel recipientUser) {
if (customKeyboardItem.getItemID().equals("customKeyboardItem1")) {// Custom keyboard item 1 was tapped by user } elseif (customKeyboardItem.getItemID().equals("customKeyboardItem2")) {// Custom keyboard item 2 was tapped by user } }});
TapCustomKeyboardManager.getInstance().addCustomKeyboardListener(object : TapCustomKeyboardListener() {overridefunsetCustomKeyboardItems( room: TAPRoomModel?, activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel? ): List<TAPCustomKeyboardItemModel> {val customKeyboardItems =ArrayList()val customKeyboardItem1 =TAPCustomKeyboardItemModel("customKeyboardItem1",getDrawable(R.drawable.keyboard_icon_1),"Hello, "+ room.getRoomName() )val customKeyboardItem2 =TAPCustomKeyboardItemModel("customKeyboardItem2","https://www.yoururl.com/image2.png","Hello, my name is "+ activeUser!!.name ) customKeyboardItems.add(customKeyboardItem1) customKeyboardItems.add(customKeyboardItem2)return customKeyboardItems }overridefunonCustomKeyboardItemTapped( activity: Activity?, customKeyboardItem: TAPCustomKeyboardItemModel?, room: TAPRoomModel?, activeUser: TAPUserModel?, @Nullable recipientUser: TAPUserModel? ) {if (customKeyboardItem!!.itemID =="customKeyboardItem1") {// Custom keyboard item 1 was tapped by user } elseif (customKeyboardItem.itemID =="customKeyboardItem2") {// Custom keyboard item 2 was tapped by user } }})
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
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.
TapCoreRoomListListener
Changes to a chat room's state, such as pin and mute events are notified through TapCoreRoomListListener. An instance of TapCoreRoomListListener can be registered from the TapCoreRoomListManager class.
The active user muted a chat room. Returns the room ID and mute expiry time of the muted room.
onChatRoomUnmuted()
The active user unmuted a chat room. Returns the room ID of the unmuted room.
onChatRoomPinned()
The active user pinned a chat room. Returns the room ID of the pinned room.
onChatRoomUnpinned()
The active user unpinned a chat room. Returns the room ID of the unpinned room.
onChatRoomDeleted()
The active user deleted a chat room. Returns the room ID of the deleted room.
TapCoreChatRoomListener
Room status events such as typing events and online status are notified through TapCoreChatRoomListener. An instance of TapCoreChatRoomListener can be registered from the TapCoreContactManager class.
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.
TapCoreContactListener
Contact related events such as block/unblock are notified through TapCoreContactListener. An instance of TapCoreContactListener can be registered from the TapCoreContactManager class.