Risposta alle modifiche di un contatto nell'elenco contatti
Prima di iniziare: Assicurarsi di aver completato l'attività
Registrazione dell'applicazione con la piattaforma BlackBerry Messenger e che la classe che visualizza i passaggi della schermata passi un riferimento all'oggetto
BBMPlatformContext associato all'applicazione.
- Importare le classi e le interfacce richieste.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.blackberry.api.bbm.platform.service.*;
import net.rim.device.api.ui.component.*;
- Creare una classe che implementa l'interfaccia PresenceListener ed estende MainScreen. Nel costruttore di questa classe Screen, passare l'oggetto BBMPlatformContext associato all'applicazione.
public class MyBBMContactListScreen implements PresenceListener extends MainScreen
{
public MyBBMContactListScreen(BBMPlatformContext platformContext)
{
}
}
- Nel costruttore, richiamare BBMPlatformContext.getContactListService().setPresenceListener() per assegnare PresenceListener all'applicazione.
public class MyBBMContactListScreen implements PresenceListener
{
public MyBBMContactListScreen(BBMPlatformContext platformContext)
{
platformContext.getContactListService().setPresenceListener(this);
}
}
- Nella classe MyBBMContactListScreen, implementare il metodo PresenceListener.presenceUpdated(). Il seguente codice visualizza una finestra di dialogo che informa l'utente delle modifiche a un contatto nell'elenco contatti di BlackBerry
Messenger. Il seguente esempio di codice utilizza un metodo helper, getEventName() , per analizzare il parametro eventType e restituire un String leggibile.
public void presenceUpdated(BBMPlatformContact contact, int eventType)
{
final String str = "[" + getEventName(eventType) + "] was changed by " + contact.getDisplayName();
Dialog.inform(str);
}
private String getEventName(int eventType)
{
String eventName;
switch(eventType)
{
case PresenceListener.EVENT_TYPE_DISPLAY_PICTURE:
eventName = "Display picture";
break;
case PresenceListener.EVENT_TYPE_DISPLAY_NAME:
eventName = "Display name";
break;
case PresenceListener.EVENT_TYPE_PERSONAL_MESSAGE:
eventName = "Personal Message";
break;
case PresenceListener.EVENT_TYPE_STATUS:
eventName = "Status";
break;
default:
eventName = "Default";
}
}
Le informazioni sono state utili? Inviateci i vostri commenti.