Development Guide
Local Navigation
- Overview of the BlackBerry Messenger SDK
- BlackBerry Messenger version dependencies
- Key classes of the BlackBerry Messenger platform
- Registering your application with the BlackBerry Messenger platform
- Interacting with contacts
- Sharing content with BlackBerry Messenger contacts
- Working with the user's profile and profile box
- Defining service listeners
- Managing your application's BlackBerry Messenger settings
- Troubleshooting
- Provide feedback
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
BlackBerry Messenger Social Platform SDK
>
Development Guide
BlackBerry Messenger SDK - 1.3
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.
-
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.*;
-
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); } }
Next topic: Define a messaging service listener
Previous topic: Defining service listeners