Define a channel listener

The following code sample assumes that you are creating this class as part of an application that requires a channel listener.
  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
  2. Create the framework for the channel listener and define each callback method's signature. The following code sample displays a message that indicates what event has occured.
    class MyChannelListener extends BBMPlatformChannelListener
    {
        public void invitationAccepted(BBMPlatformConnection connection, BBMPlatformContact contact)
        {
            Dialog.inform(contact.getDisplayName() + " has accepted your invitation.");
        }
    
        public void invitationDeclined(BBMPlatformConnection connection, String contactDisplayName) 
        {
            Dialog.inform(contactDisplayName + " has declined your invitation.");
        }
       
        public void invitationFailed(BBMPlatformConnection connection, String inviteeName, int reasonCode) 
        {
            Dialog.inform(inviteeName + " has failed to receive your invitation. Error: " + reasonCode);
        }
    
    
        public void contactLeft(BBMPlatformConnection connection, BBMPlatformContact contact) 
        {
            Dialog.inform(contact.getDisplayName() + " has left the application.");
        }
    
        //NOTE: The message parameter is received as a data array. This method converts message to a String before displaying.
        public void dataReceived(BBMPlatformConnection connection, BBMPlatformContact fromContact, BBMPlatformData message)
        {
            Dialog.inform(fromContact.getDisplayName() + ": " + new String(message.getData()));
        }
    
        //NOTE: param is a custom parameter defined by the application and passed in from the sender of the invitation
        public void invitationReceived(BBMPlatformConnection connection, BBMPlatformContact contact, String param)
        {
            Dialog.inform(contact.getDisplayName() + ": " + param);
        }
    
        public void invitationsSent(BBMPlatformConnection connection, int count)
        {
            Dialog.inform("I've sent " + count + " invitations.");
        }
    
        public void joinFailed(BBMPlatformConnection connection, BBMPlatformContact inviter, int reasonCode)
        {
            Dialog.inform("The user has failed to join the session. Error: " + reasonCode);
        }
       
    }

Was this information helpful? Send us your comments.