세션 수신기 정의

다음 예제에서는 세션 수신기가 필요한 프로그램의 일부로 이 클래스를 생성한다고 가정합니다.
  1. 필요한 클래스와 인터페이스를 가져옵니다.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.blackberry.api.bbm.platform.service.*;
    import net.rim.device.api.ui.component.*;
  2. 세션 수신기의 프레임워크를 생성하여 각 콜백 메서드의 서명을 정의하고 필요에 따라 메서드를 구현합니다. 다음 코드 샘플은 사용자에게 변경 사항을 알려주는 대화 상자를 표시합니다.
    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);                    
        }  
    }

이 정보가 도움이 되었습니까? 의견을 보내 주십시오.