简体   繁体   中英

cordova plugin geofence - Android can't receive transition events in the background

I'm building a location-aware Cordova app for iOS and Android utilizing this Geofencing plugin .

When I started to test my implementation on my Android device, I discovered that geofence transitions are not handled in the background as soon as they are detected, but rather they "collect" and then fire all at once the next time the app is launched manually (by "fire" I mean invoke the window.geofence.onTransitionReceived() method).

To clarify, I disabled the included notifications feature, only expecting my app to have the events delivered to it in order to update our remote server silently in the background. While, the iOS version successfully receives those transitions in the background, I can't figure what's wrong about Android here...

Does anyone know this plugin and how to utilize it appropriately for Android? Was there something I missed?

Thanks, Dor.

I had a similar problem and raised this issue: https://github.com/cowbell/cordova-plugin-geofence/issues/53 . It appears that you cannot execute javascript in the background on Android, so this is the limitation.

My solution was to write my own Java in GeofencePlugin.java, changing the following method to meet my needs (in my case creating an HttpClient and sending a POST request)

public static void onTransitionReceived(List<GeoNotification> notifications)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM