petermetz / cordova-plugin-ibeacon

An iBeacon plugin for Phonegap / Cordova 3.x and upwards. Supports both iOS and Android (contributions are welcome)
Apache License 2.0
726 stars 373 forks source link

Constant Region Entry/Exit Events on Android 7.0 Nougat Plus Compatibility Issue with BluetoothLE plugin #253

Open bobhuang1 opened 8 years ago

bobhuang1 commented 8 years ago

Long time user, first time poster.

I have this project that uses both Peter's cordova-plugin-ibeacon and the cordova-plugin-bluetoothle plugin. It was working great on Android 4.4 through 6 and all IOS versions. The idea is simple, using the iBeacon plugin, once the device enters a particular iBeacon's range, it will stop iBeacon monitoring and start scanning for a BTLE scanner using cordova-plugin-bluetoothle and connect and perform its operations.

I just started trying to get this project to work with an Android 7.0 (Nougat) on Nexus 5X.

What I observed is that there are two issues:

  1. In iBeacon Monitoring mode, the iBeacon plugin keeps firing Region Entry/Exit events every at about every 5 seconds. If I add raning, it behaves the same way. I read something in the AltBeacon issues that about something like this: https://github.com/AltBeacon/android-beacon-library/issues/418 But after I updated the AltBeacon jar to the latest 2.9.1 version into this plugin and re-compile, this issue still exists.
  2. Whenever I start iBeacon monitoring mode first, and stop monitoring, and then try to scan with the BTLE plugin, the StartScan() just hang and can't find any BTLE scanner. It would seem that the iBeacon plugin somehow prevents the BTLE plugin from finding any BTLE device even through the StartScan event comes back with "success".

I suspect this has something to do with the Background Optimization with Android 7.0: https://developer.android.com/topic/performance/background-optimization.html But I do not know the native platform enough to actually confirm that.

Thanks much guys!

omanthey commented 8 years ago

Hello,

I am struggling with the same behaviour that seems to be based on on the "background-optimization" in Android 7.

Is there any solution so far?

Oliver

bobhuang1 commented 8 years ago

No solution yet, I have to disable plugin on Android 7 phones for now.

omanthey commented 8 years ago

The only workaround I can see momentarily is to set the ForegroundBetweenScanPeriod accordingly in config.xml

preference name="com.unarin.cordova.beacon.android.altbeacon.ForegroundBetweenScanPeriod" value="5000"

The disadvantage of this approach is that we get updates on the sorrounding beacons now only every 5 seconds. In my case where I am developing an app to be used within a museums exhibition where a couple of beacons are pleced to determine where the visitor is located and trigger according events for the specific location it means that within this 5 seconds a couple of beacons may be passed by the visitor without the app noticing that ... Very bad :-(

parkej60 commented 8 years ago

@bobhuang1 Where / how did you get the updated JAR file? I would like to test this out but I'm not sure how to generate a JAR file.

parkej60 commented 8 years ago

@omanthey What config.xml file are you referring too?

omanthey commented 8 years ago

@parkej60: I#m referring to the cordoca projetx main config.xml. There you can configure the ForegroundBetweenScanPeriod. I configured this originally to a value of 1000ms so I got BLE Beacon values every second. But with the changes in Android 7 only 6 times in 30 seconds the underlying BLE System can becalled (every further call will be blocked). so I mofdified the value to 5000 ms to hit the 30 sec. interval. This way my system works (beacon installation to lead visitors through a museums exhibition) but it is much less responsive. Within 6 seconds a visitor may procced so far that individual beacons will be ignored :-(

I still hope there will be some solutiuon for this problem in the future ...

parkej60 commented 8 years ago

Ok. After adjusting the power on the beacons I'm now seeing the exact same issue as documented above. Works well on Android 6.0, but seeing the toggling in and out of regions when in Android 7.0

bobhuang1 commented 7 years ago

@parkej60 Sorry I have not checked this page for while, I downloaded the latest jar from: http://altbeacon.github.io/android-beacon-library/download.html I also tried downloading the source and compile myself: https://github.com/AltBeacon/android-beacon-library Always the same issue. However as @omanthey pointed out, setting ForegroundBetweenScanPeriod to 5000ms works but much less responsive. I guess that's something we have to live with on Android 7.

bobhuang1 commented 7 years ago

I have an idea, is it possible to set ForegroundBetweenScanPeriod to 5000ms when android is 7.0 and to the default 1000ms when it's not? Does the config.xml platform section allow specifying os version? Thanks.