Menentukan pendengar saluran

Contoh kode berikut mengasumsikan bahwa Anda membuat kelas ini sebagai bagian dari aplikasi yang memerlukan pendengar saluran.
  1. Impor kelas dan antarmuka yang diperlukan.
    import net.rim.blackberry.api.bbm.platform.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
  2. Buat kerangka kerja untuk pendengar saluran dan tentukan setiap tanda tangan metode panggilan balik. Contoh kode berikut menampilkan pesan yang menunjukkan kejadian apa yang telah terjadi.
    class MyChannelListener extends BBMPlatformChannelListener
    {
        public void invitationAccepted(BBMPlatformConnection connection, BBMPlatformContact contact)
        {
            Dialog.inform(contact.getDisplayName() + " has accepted your invitation.");
        }
        public void invitationDeclined(BBMPlatformConnection connection, String contactDisplayName) 
        {
            Dialog.inform(contactDisplayName + " has declined your invitation.");
        }
        public void invitationFailed(BBMPlatformConnection connection, String inviteeName, int reasonCode) 
        {
            Dialog.inform(inviteeName + " has failed to receive your invitation. Error: " + reasonCode);
        }
        public void contactLeft(BBMPlatformConnection connection, BBMPlatformContact contact) 
        {
            Dialog.inform(contact.getDisplayName() + " has left the application.");
        }
        //NOTE: The message parameter is received as a data array. This method converts message to a String before displaying.
        public void dataReceived(BBMPlatformConnection connection, BBMPlatformContact fromContact, BBMPlatformData message)
        {
            Dialog.inform(fromContact.getDisplayName() + ": " + new String(message.getData()));
        }
        //NOTE: param is a custom parameter defined by the application and passed in from the sender of the invitation
        public void invitationReceived(BBMPlatformConnection connection, BBMPlatformContact contact, String param)
        {
            Dialog.inform(contact.getDisplayName() + ": " + param);
        }
        public void invitationsSent(BBMPlatformConnection connection, int count)
        {
            Dialog.inform("I've sent " + count + " invitations.");
        }
        public void joinFailed(BBMPlatformConnection connection, BBMPlatformContact inviter, int reasonCode)
        {
            Dialog.inform("The user has failed to join the session. Error: " + reasonCode);
        }
    }

Apakah informasi ini berguna? Kirimkan komentar Anda kepada kami.