0

I am trying to use Android Beacon Library in an app that runs as a background service. I bind beaconManager on my service starting. I am unbinding it in onDestroy callBack.

I am setting iBeaconManager with setBackGroundScanPeriod and setBackGroundBetweenScanPeriod with some default values .

Whenever I run the application my service is called and automatically it is scanning for the beacons. The callback methods didEnterRegion and didExitRegion are called based on beacon availability and in didEnterRegion callBack method I am calling startRangingBeaconsInRegion.

Everything works fine when i was in the same region. And if I leave for a far location and reentered the same location it is not scanning the beacons.

Does location change really effect beacon scanning ? or else will it scan only for specific time? Anyone Please help me through this. Thanks in Advance.

Makoto
  • 765
  • 2
  • 17
  • 45
SriramTej
  • 21
  • 5

1 Answers1

0

It is impossible to say for sure without seeing the code, but I suspect that the library is stopping scanning at some point in your application. You mention a background service that binds and unbinds to the BeaconManager. Are you sure your background service is still running?

One way to see if the BeaconService is still scanning is to enable debug logging. Once this is done on your app, you can connect the app to your computer via a usb cable, and look for debug output from the BeaconService using the line below.

adb logcat | grep BeaconService

If it is scanning for beacons, you should see lines like:

D/BeaconService(14202): Waiting to stop scan for another 1100 milliseconds
D/BeaconService(14202): Scan started
D/BeaconService(14202): Waiting to stop scan for another 100 milliseconds
D/BeaconService(14202): Done with scan cycle

The time intervals may be longer depending on whether the library is in background mode or not.

Another alternative is to simplify your approach by not binding and unbinding to the BeaconManger in your service, and instead attach the library to an Android Application class. This is the preferred approach, and uses the RegionBootstrap and BackgroundPowerSaver as described in the reference application shown here: https://github.com/AltBeacon/android-beacon-library-reference/blob/master/src/org/altbeacon/beaconreference/BeaconReferenceApplication.java

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Thanks for the response @davidgyoung and the BackgroundPowerSaver you mentioned is available in new library as of now i am using the prior release and yes the background service is running and what i even found was when the screen of my phone is locked automatically bluetooth is stopping the scan . Does the library is stopping the scan whenever the screen turned off? – SriramTej Oct 13 '14 at 12:11
  • It would be very helpful if you could attach some debug logs like in my answer above. With the 0.x version of the library, debug is enabled with IBeaconManager.setDebug(true) – davidgyoung Oct 13 '14 at 17:43