Een sessielistener definiëren

In het volgende codevoorbeeld wordt aangenomen dat u deze klasse als onderdeel maakt van een toepassing die een sessielistener vereist.
  1. Importeer de noodzakelijke klassen en interfaces.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.service.*;
    import net.rim.device.api.ui.component.*;
  2. Maak het kader voor de sessielistener door de handtekening van elke retouraanroepmethode te definiëren en implementeer de methode zoals vereist. In het volgende codevoorbeeld wordt een dialoogvenster weergegeven waarin de gebruiker wordt geïnformeerd over de wijziging die heeft plaatsgevonden.
    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);                    
        }  
    }
Volgend onderwerp: Problemen oplossen

Was deze informatie nuttig? Stuur ons uw opmerkingen.