Definieren eines Sitzungslisteners

In dem folgenden Beispiel wird davon ausgegangen, dass Sie diese Klasse als Teil einer Anwendung erstellen, die einen Sitzungslistener benötigt.
  1. Importieren Sie die erforderlichen Klassen und Schnittstellen.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.service.*;
    import net.rim.device.api.ui.component.*;
  2. Erstellen Sie das Framework für den Sitzungslistener, indem Sie die Signatur jeder Rückrufmethode definieren, und implementieren Sie die Methode entsprechend. Das folgende Codebeispiel zeigt einen Dialog an, der den Benutzer über die erfolgte Änderung informiert.
    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);                    
        }  
    }

Waren diese Informationen hilfreich? Senden Sie uns Ihren Kommentar.