Event Handlers
Channelize Android API SDK provides a simple way to notify client applications for real-time events happening across the Application. Achieve this by registering event callback for the events. Whenever an event occurs, the respective callback is executed. You can also add multiple callbacks for an event.
Add Connection Event Handler
To receive events happening for connection (connected/disconnected/all real-time events) from Channelize.io server register ChannelizeConnectionHandler in Channelize class.
Implement the following functions/events to get the information related to the connection.
Channelize.addConnectionHandler(new ChannelizeConnectionHandler() {
@Override
public void onConnected() {
// Invoke when the Android SDK establishes a successful connection with the Channelize.io server.
}
@Override
public void onDisconnected() {
// Invoke when the Android SDK disconnects from the Channelize.io server.
}
@Override
public void onRealTimeDataUpdate(String topic, String responseMessage) {
}
});
Remove Connection Event Handler
To remove connection event handler add following code.
Channelize.removeConnectionHandler(this);
Add User Event Handler
To receive events happening for the user from Channelize.io server you need to register ChannelizeUserEventHandler in Channelize class.
Implement the following functions/events to get the information related to the users.
Channelize.addUserEventHandler(new ChannelizeUserEventHandler() {
@Override
public void onUserStatusUpdated(User user) {
// Invoke once the user status is updated i.e offline to online and online to offline
}
@Override
public void onUserBlocked(User user) {
// Invoke once the user is blocked from conversation
}
@Override
public void onFriendAdded(User user) {
// Invoke when two users become friends.
}
@Override
public void onFriendRemoved(String userId) {
// Invoke when a user removes someone from its friend list.
}
@Override
public void onUserBlocked(boolean isSelfBlockUnBlock, String blockedUserId) {
// Invoke when a user blocks another user.
}
@Override
public void onUserUnblocked(boolean isSelfBlockUnBlock, String unBlockedUserId) {
// Invoke when a user unblocks another user.
}
@Override
public void onOnline(User user) {
// Invoke when a user appears online.
}
@Override
public void onOffline(User user) {
// Invoke when a user goes offline.
}
@Override
public void onUserUpdated(User user) {
// Invoke when a user's information is updated.
}
});
Remove User Event Handler
To remove user event handler add following code.
Channelize.removeUserEventHandler(this);
Add Conversation Event Handler
To receive events happening in the conversations from Channelize.io server you need to register ChannelizeConversationEventHandler in Channelize class.
Implement the following functions/events to get the information related to the conversations.
Channelize.addConversationEventHandler(new ChannelizeConversationEventHandler() {
@Override
public void onConversationUpdated(Conversation conversation) {
// Invoke when there is an update in a conversation i.e Title, Profile Image or Members list.
}
@Override
public void onConversationDeleted(Conversation conversation) {
// Invoke when a conversation is deleted. This event will update the user who has deleted the conversation.
}
@Override
public void onConversationCleared(Conversation conversation) {
// Invoke when a conversation is cleared. This event will update the user who has cleared the conversation.
}
@Override
public void onUserJoined(Conversation conversation) {
// Invoke when a user is added to a conversation.
}
@Override
public void onUserLeft(Conversation conversation) {
// Invoke when a user is removed from a conversation or left a conversation.
}
@Override
public void onUserMuteStatusUpdated(String conversationId, boolean isMute) {
// Invoke when a user mutes or unmutes a conversation. This event will update the user who has performed this action.
}
@Override
public void onAdminAdded(Conversation conversation, Member member) {
// Invoke when a user becomes admin in any Conversation
}
@Override
public void onMessageReceived(Message message) {
//Invokes when a new message is received
}
@Override
public void onMessagesDeleted(List<Message> mMessageList) {
//Invokes when messages are deleted by the logged-in user
}
@Override
public void onMessagesDeletedForEveryOne(List<Message> mMessageList) {
//Invokes when messages are deleted for all the users present in the conversation
}
@Override
public void onMemberAdded(Conversation conversation, List<Member> mMemberList) {
//Invokes when new members are added in group conversation
}
@Override
public void onMemberRemoved(Conversation conversation, List<Member> mMemberList) {
//Invokes when member is removed from the group conversation
}
@Override
public void onTypingStatusUpdated(String conversationId, String userId, boolean isTyping) {
}
@Override
public void onReadMessageToSelf(Conversation conversation, User user, String timeStamp) {
}
@Override
public void onReadMessageToOwner(Conversation conversation, User user, String timeStamp) {
}
});
@Override
public void onReadMessageToSelf(String conversationId, String messageId) {
// Invoke when a user reads the message sent by another user. This event will update the message recipient who read the message.
}
});
Remove Conversation Event Handler
To remove conversation event handler add following code.
Channelize.removeConversationEventHandler(this);