Menentukan pendengar perubahan konteks
Contoh berikut mengasumsikan bahwa Anda membuat kelas internal privat sebagai bagian dari aplikasi yang memerlukan pendengar perubahan konteks.
- Impor kelas dan antarmuka yang diperlukan.
import net.rim.blackberry.api.bbm.platform.*;
import net.rim.device.api.ui.component.*;
- Buat kerangka kerja untuk pendengar layanan perubahan konteks, dengan menentukan metode accessChanged(). Parameter accessErrorCode adalah salah satu bidang dari kelas BBMPlatformContext (contohnya, ACCESS_BLOCKED_BY_IT_POLICY). Contoh kode berikut menampilkan kotak dialog yang memberi tahu pengguna mengenai perubahan apa saja yang telah terjadi.
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*/
}
}
Apakah informasi ini berguna? Kirimkan komentar Anda kepada kami.