androidbluetooth-lowenergyaltbeaconbeacon

Not detecting beacons if I kill the app from the Task Manager


I'm using Altbeacon to detect iBeacons.

If the app is in foreground or if the app is in background through the "home" button works fine. In both cases works perfectly.

But, when I try to detect beacons after killing the app through the Task Manager, there isn't any way to detect any beacon. I'm going crazy.

I'm using the last version of Altbeacon, and this is my code (Application class):

public void startBeaconScan() {

        beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().
        setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));  //iBeacon layout

        beaconManager.setBackgroundBetweenScanPeriod(500);
        beaconManager.setBackgroundScanPeriod(500);
        beaconManager.setForegroundBetweenScanPeriod(500);
        beaconManager.setForegroundScanPeriod(500);

        beaconManager.setRegionStatePeristenceEnabled(false);
        beaconManager.bind(this);

        region = new Region("myMonitoringUniqueId", Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"), null, null);
        new RegionBootstrap(this, region);
    }

I've read a lot of posts but I've not found any solution yet.

Smartphones used to test: Xiaomi Redmi Note 2, Samsung Galaxy S5

---------------- UPDATE ------------------------

Code for the RegionBootstrap callbacks:

@Override
    public void didDetermineStateForRegion(int arg0, Region arg1) {
        Log.d(TAG, "Got a didDetermineStateForRegion call: " + arg1.getId1());
    }

    @Override
    public void didEnterRegion(Region arg0) {
        Log.d(TAG, "Got a didEnterRegion call: " + arg0.getId1());
    }

    @Override
    public void didExitRegion(Region arg0) {
        Log.d(TAG, "Got a didExitRegion call: " + arg0.getBluetoothAddress());
    }

For each one I've the default logs, and none of them is shown after the app is killed.


Solution

  • In order to auto launch you app to scan for beacons after being killed, the RegionBootstrap must be configured in the onCreate method of a custom Application class not an Activity.

    See here for more info: http://altbeacon.github.io/android-beacon-library/background_launching.html