Informatie verkrijgen over hoe uw toepassing binnen BlackBerry Messenger wordt aangeroepen
U kunt BBMPlatformContextListener.appInvoked() gebruiken om vast te leggen hoe uw app binnen BlackBerry Messenger werd aangeroepen en om gerelateerde gegevens te verzamelen, zoals de huidige gebruiker, contactpersoon, PPID en profielvakitems. U kunt deze informatie gebruiken om te leren hoe de BBM-functies die in uw app zijn geïntegreerd worden gebruikt. U kunt bijvoorbeeld het gedrag van uw app wijzigen zodat deze opent in de context waarin deze normaal wordt aangeroepen, zoals wanneer een prestatielijst wordt weergegeven in het profielvak van een gebruiker. Het kan u ook helpen om het belang van deze functies voor uw app vast te stellen.
De volgende tabel toont de contextuele informatie die BBMPlatformContextListener.appInvoked(reason, param, user) met elke redenconstante kan vastleggen:
| Redenconstante |
App wordt aangeroepen wanneer de huidige gebruiker klikt |
Param |
Gebruiker |
|---|---|---|---|
| INVOKE_PROFILE_BOX_ITEM |
Het profielvakitem van een gebruiker voor de toepassing |
De UserProfileBoxItem waarop is geklikt |
De gebruiker op wiens profielvakitem is geklikt (kan de huidige gebruiker zijn) |
| INVOKE_PROFILE_BOX |
De profielvakkoptekst van een gebruiker voor de toepassing |
null |
De gebruiker op wiens profielvak is geklikt (kan de huidige gebruiker zijn) |
INVOKE_PERSONAL_MESSAGE |
De koppeling 'persoonlijk bericht' van de app in het profiel van een contactpersoon |
De persoonlijke berichtenreeks (exclusief de koppeling naar de app) |
De contactpersoon op wiens koppeling van een persoonlijk bericht is geklikt |
INVOKE_CHAT_MESSAGE |
De koppeling naar de app in het chatbericht van een contactpersoon |
null |
De contactpersoon op wiens koppeling chatbericht is geklikt |
Laten we eens naar enkele scenario's kijken
public appInvoked(final int reason, final Object param, final Presence user)
{
/* Scenario 1: The current user clicks a contact’s profile box header
* for the app. */
if(reason == BBMPlatformContext.INVOKE_PROFILE_BOX)
{
int ppid = getPPID(user);
/* Add code to capture all the items in the user's profile box,
* for example, activities and achievements) /*
}
/* Scenario 2: The current user clicks a contact’s profile box item for the app.
* The app can capture whose profile box was clicked, and the associated profile
* box item. */
if(reason == BBMPlatformContext.INVOKE_PROFILE_BOX_ITEM)
{
Int ppid = getPPID(user);
UserProfileBoxItem item = (UserProfileBoxItem) param;
// display the profile box item, for example, a game score
int score = Integer.parseInt(item.getCookie());
}
/* Scenario 3: The current user clicks a contact’s personal message link
* in a contact's profile. The app can capture whose personal message
* was clicked and the personal message (minus the app link).*/
if(reason == BBMPlatformContext.INVOKE_PERSONAL_MESSAGE)
{
int ppid = getPPID(user);
String personalMessage = (String) param;
}
/* Scenario 4: The current user clicks a contact’s chat message link
* in a contact's chat message. The app can capture whose chat message
* link was clicked.*/
if(reason == BBMPlatformContext.INVOKE_CHAT_MESSAGE)
{
int ppid = getPPID(user);
// Add code to start an activity with the contact
}
}
// A generic function to obtain a user's unique ID
public static int getPPID (Presence user)
{
if (user instanceof UserProfile)
{ // returns the current user's PPID
return ((UserProfile) user).getPPID();
}
else if(user instanceof BBMPlatformContact)
{ // returns the contact's PPID
return ((BBMPlatformContact) user).getPPID();
}
}