androidibeacon-android

How does the library detect a beacon in 5 seconds after app kill for platforms 5 - 7?


I was going through the table here http://www.davidgyoungtech.com/2017/08/07/beacon-detection-with-android-8 and I am confused as to how does the library achieve detection time of 5 seconds after app kill on Android platforms 5-7. This is what the link says - Apps on Android 4.3-7.x used long-running background services or alarms to periodically look for beacons in the background. As far as I know, alarms cannot be set for less than 15 minutes so how does the 5 second thing work?


Solution

  • My blog post's detection times table that you mention (reproduced below) says that detection times are 5 seconds on Android 5.0-7.x. (Clarification: it does not make this claim for 4.x.) This is possible on 5.x-7 by using a long-running filtered low-power scan using an API introduced in Android 5.0. Here's the code that sets that up.

    What this does is puts the Bluetooth LE chip in a low power mode that automatically wakes up if any packet matching the expected filter patter is seen. After the wake up, the Android OS delivers the scan result to the library which then sends a callback to the application via didEnterRegion or didRangeBeaconsInRegion. This process typically takes just a few seconds after the packet appears.

    These scanning times have nothing to do with Alarms. On Android 4.x-7.x, the AlarmManager is used for a completely different purpose -- to keep a long-running background service alive. An Alarm repeatedly reset for 5 minutes in the future, and as long as the service keeps running it never goes off. If the app is killed due to low memory or the user swiping it off the screen, this alarm will fire a BroadcastReceiver which triggers the long-running scanning service to start itself again.

    To my knowledge there is nothing on Android 4.x-7.x that limits Alarms from running more than once every 15 minutes. You may be thinking of a limitation on Android 8+ that restricts periodic JobScheduler items to every 15 minutes or more.

    Android Beacon Library Detection Times: Android Beacon Library Detection Times