Skip to content

Bootstrap Monitoring

Alann Maulana edited this page Nov 19, 2016 · 1 revision

When we expect the monitoring in our app to work at all times, no matter which activity is currently in use. To achieve that, we will instantiate in a subclass of the Application class. Start by creating a new MyApplication Java Class that extend to android.app.Application:

public class MyApplication extends Application implements CBBootstrapListener {
    private static final String TAG = MyApplication.class.getSimpleName();

    @Override
    public void onCreate() {
        super.onCreate();

        // initializing Cubeacon SDK
        Cubeacon.initialize(this);

        // create region for scanning
        CBRegion region = new CBRegion("com.eyro.cubeacon.bootstrap_region",
                        UUID.fromString("CB10023F-A318-3394-4199-A8730C7C1AEC"), 1, 284);
        // setup region scanning when OS boot completed
        CBBootstrapRegion.setup(this, region);
    }

    @Override
    public void didEnterRegion(CBRegion region) {
        Log.d(TAG, "Entering region: " + region);
    }

    @Override
    public void didExitRegion(CBRegion region) {
        Log.d(TAG, "Exiting region: " + region);
    }

    @Override
    public void didDetermineStateForRegion(MonitoringState state, CBRegion region) {
        Log.d(TAG, "Region: " + region + " change state to: " + state.name());
    }
}

IMPORTANT: Don't forget to implement CBBootstrapListener to your application class. Then declare it in the AndroidManifest.xml file:

<application
    <!-- add this: -->
    android:name=".MyApplication"
    <!-- etc. ... -->

NOTE: That CBBootstrapRegion class registers an internal CBMonitoringListener with the Cubeacon. If you use the CBBootstrapRegion, your application must not manually register a second CBMonitoringListener, otherwise it will unregister the one configured by the CBBootstrapRegion, effectively disabling it.

Clone this wiki locally