Definieren eines Kontextänderungs-Listeners
Im folgenden Beispiel wird davon ausgegangen, dass Sie eine private innere Klasse als Teil einer Anwendung erstellen, die einen Kontextänderungs-Listener erfordert.
- Importieren Sie die erforderlichen Klassen und Schnittstellen.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.device.api.ui.component.*;
- Erstellen Sie das Framework für den Kontextänderungs-Listener, indem Sie die accessChanged()-Methode definieren. Der accessErrorCode-Parameter ist eines der Felder der BBMPlatformContext-Klasse (beispielsweise ACCESS_BLOCKED_BY_IT_POLICY). Das folgende Codebeispiel zeigt Dialogfelder an, die den Benutzer über die erfolgte Änderung informieren.
class MyBBMPlatformContextListener extends BBMPlatformContextListener
{
public void accessChanged(boolean isAccessAllowed, int accessErrorCode)
{
if(isAccessAllowed)
{
Dialog.inform("Access to the platform context is now allowed.");
}
else
{
Dialog.inform("Access to the platform context is now disallowed because
of error:" + accessErrorCode);
}
}
public void appInvoked(int reason, Object param)
{
/*code for handling different contexts for invocation:
<reason> is a constant in BBMPlatformApplication prepended
with INVOKE, which tells you why this app was invoked and by
whom
<param> is an object representing a custom paramater with
more information about the invocation context*/
}
}
Waren diese Informationen hilfreich? Senden Sie uns Ihren Kommentar.