Définir un écouteur de canal
L'échantillon de code suivant suppose que vous créez cette classe comme faisant partie d'une application qui nécessite un écouteur de canal.
- Importez les classes et les interfaces requises.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
- Créez le cadre pour l'écouteur de canal et définissez la signature de chaque méthode de rappel. L'échantillon de code suivant affiche un message qui indique que l'événement a eu lieu.
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);
}
}
Ces informations vous ont-elles été utiles ? Envoyez-nous vos commentaires.