Search code examples
androidbluetoothibeaconibeacon-androidandroid-ibeacon

iBeacon(Kontakt Beacon) Region Monitoring In android


I am working on an application which is base on beacon devices. Scenario is that when ever user go to nearby by beacon device range he will get notification.

For that i am trying to monitoring the region in background while Bluetooth is in off state, but its not working i.e. i am not getting any callback i.e. "onRegionEntered" or "onRegionAbandoned".

So the question is that is this possible to monitor a region when Bluetooth of phone is OFF (offcource Location (GPS) is ON), if yes then how , Please provide any sample or code snippet.

As we have "Kontakt" iBeacon devices so i am using kontakt sdk. Kontakt SDK

I am using this configuration for region monitoring

 private void configureProximityManager() {
    proximityManager.configuration()
            .scanMode(ScanMode.BALANCED)
            .activityCheckConfiguration(ActivityCheckConfiguration.MINIMAL)
            .forceScanConfiguration(ForceScanConfiguration.MINIMAL)
            //.deviceUpdateCallbackInterval(2000)
            .rssiCalculator(RssiCalculators.newLimitedMeanRssiCalculator(5))
            .monitoringEnabled(true)
            .monitoringSyncInterval(3);

    addReasonForMonitoring();

    //GcmNetworkManager.getInstance(this).cancelTask();
}

private void addReasonForMonitoring(){
    beaconRegions.clear();
    beaconRegions.add(getBeaconReason());
    proximityManager.spaces().iBeaconRegions(beaconRegions);
}

private BeaconRegion getBeaconReason(){
    return new BeaconRegion.Builder()
            .setIdentifier(FORKSPOT_REASON)
            .setProximity(UUID.fromString(BEACON_UUID))
            //.setMajor(restBeaconsInfo.getMajor())
            //.setMinor(restBeaconsInfo.getMinor())
            .build();

}
 private void startMonitoring() {
    Log.e(TAG,"start monitoring");
    int checkSelfPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);

    if ((PackageManager.PERMISSION_GRANTED == checkSelfPermission) /*&& Utils.getBluetoothState()*/) {
        proximityManager.connect(new OnServiceReadyListener() {
            @Override
            public void onServiceReady() {
                Log.e(TAG, "startScanning");
                proximityManager.startScanning();
            }
        });
    } else {
        Log.e(TAG, "Permission not guaranteed or bluetooth is off");
    }
}

Solution

  • If Bluetooth is off, you cannot detect Bluetooth LE beacons. This is an operating system restriction and not specific to any one beacon SDK.

    While this may seem obvious, it is a fair question given that Google internally scans WiFi networks for location purposes even if WiFi is turned off. The same, however, is not true for Bluetooth.