Menentukan pendengar sesi

Contoh berikut mengasumsikan bahwa Anda membuat kelas ini sebagai bagian dari aplikasi yang memerlukan pendengar sesi.
  1. Impor kelas dan antarmuka yang diperlukan.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.service.*;
    import net.rim.device.api.ui.component.*;
  2. Buat kerangka kerja untuk pendengar sesi, dengan mendefinisikan tanda tangan setiap metode panggilan balik, dan terapkan metode tersebut sebagaimana diperlukan. Contoh kode berikut menampilkan dialog yang memberi tahu pengguna tentang perubahan yang telah terjadi.
    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);                    
        }  
    }

Apakah informasi ini berguna? Kirimkan komentar Anda kepada kami.