Search code examples
androidbluetoothbluetooth-lowenergyibeaconandroid-bluetooth

auto launch application beacon every time when detect beacon signal


I follow this reference here and i wonder

  1. That it's possible to launch my application every times when I'm enter the beacon region or I'm already in beacon region and my device detect the beacon signal. Because now boostrapnotifier class still recall when power connection change

2.Can I define the radius of beacon region such as 5 meters. Because now radius is too wide for my use case.


Solution

  • In general this is possible, yes.

    The RegionBootstrap class is designed to auto launch your app into the background to scan for beacons, and send callbacks whenever you enter/exit a beacon region. Because the operating system may kill your app to save memory, the library is designed to re-launch the app so its background scanning service can continue operating under a few conditions:

    1. Within 5 minutes of being killed using an Android AlarmManager.
    2. If the above fails, on a power connect/disconnect operation.
    3. On phone boot.

    Following the reference you mention, this behavior should be automatic.

    While you can't define a radius of a Region, you can add filtering logic that does something similar. Once you get a callback to didEnterRegion, start ranging for beacons in that region. In the ranging callback, if you see that beacon.getDistance() < 5.0 you can execute your logic that you want to happen only if the beacon is less than five meters away.