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
>
개발자 문서
>
BlackBerry Messenger Social Platform SDK
>
Development Guide
BlackBerry Messenger SDK - 1.3
Define a session listener
The following
example assumes that you are creating this class as part of an application that
requires a session listener.
-
Import the required classes and interfaces.
import net.rim.blackberry.api.bbm.platform.*; import net.rim.blackberry.api.bbm.platform.service.*; import net.rim.device.api.ui.component.*;
-
Create the framework for the session listener, defining each
callback method's signature, and implement the method as required. The
following code sample displays a dialog that informs the user of the change
that has occured.
class MySessionListener extends BBMPlatformSessionListener { public void invitationAccepted(BBMPlatformConnection connection, BBMPlatformContact contact) { Dialog.inform(contact.getDisplayName() + " has accepted the session invitation "); } public void invitationDeclined(BBMPlatformConnection connection, String contactDisplayName) { Dialog.inform(contactDisplayName + " has declined the session invitation ")); } public void joinFailed(BBMPlatformConnection connection, BBMPlatformContact inviter, int reasonCode) { Dialog.inform(inviter.getDisplayName() + " has rejected the session join request due to the reason: " + Integer.toString(reasonCode)); } public void invitationFailed(BBMPlatformConnection connection, String inviteeName, int reasonCode) { Dialog.inform(inviteeName + "cannot accept the channel invite due to the reason: " + Integer.toString(reasonCode)); } public void contactsJoined(BBMPlatformSession session, BBMPlatformContactList contactList) { if (contactList != null) { Enumeration contacts = contactList.getAll(); while (contacts.hasMoreElements()) { BBMPlatformContact contact = (BBMPlatformContact)contacts.nextElement(); Dialog.inform(contact.getDisplayName() + " has joined the session."); } } } public void contactsRemoved(BBMPlatformSession session, BBMPlatformContact removedBy, BBMPlatformContactList contactList) { if (contactList != null) { Enumeration contacts = contactList.getAll(); while (contacts.hasMoreElements()) { BBMPlatformContact contact = (BBMPlatformContact)contacts.nextElement(); Dialog.inform(contact.getDisplayName() + " has been removed from the session by " + removedBy.getDisplayName()); } } } public void contactLeft(BBMPlatformConnection connection, BBMPlatformContact contact) { Dialog.inform(contact.getDisplayName() + " has left the session "); } public void dataReceived(BBMPlatformConnection connection, BBMPlatformContact fromContact, BBMPlatformData data) { Dialog.inform("session msg from:" + fromContact.getDisplayName() + " : " + data.getDataAsString())); } public void broadcastDataReceived(BBMPlatformSession session, BBMPlatformContact sender, BBMPlatformData data) { Dialog.inform("broadcasting msg from:" + sender.getDisplayName() + " > " + data.getDataAsString())); } public void invitationReceived(BBMPlatformConnection connection, BBMPlatformContact contact, String param) { Dialog.inform(contact.getDisplayName() + " is inviting me to join the session ")); } public void invitationsSent(BBMPlatformConnection connection, int count) { Dialog.inform(count + " session invitation(s) sent")); } public void sessionEnded(BBMPlatformContact contact) { Dialog.inform(contact.getDisplayName() + " ends the session"); } public void joinRequestReceived(BBMPlatformConnection connection, BBMPlatformIncomingJoinRequest request, String param) { _incomingJoinRequest = request; Dialog.inform("Incoming Session Join request received from " + request.getRequester().getDisplayName() + ". Please Accept or Decline",FOCUSABLE); } public void joinRequestCancelled(BBMPlatformConnection connection, BBMPlatformIncomingJoinRequest request, int reasonCode) { Dialog.inform("The join request has been cancelled by " + request.getRequester().getDisplayName() + " for reason: " + reasonCode,FOCUSABLE); } }
Previous topic: Define a context change listener