I've been toying with React Native's HeadlessJS
BackgroundGeolocation can easily be plugged into this for you in about 15 minutes.
If anyone's interested, I'm working on a sample here
The Javascript end looks like this
index.android.js
import HeadlessService from './components/HeadlessService';
.
.
.
AppRegistry.registerHeadlessTask('HeadlessService', () => HeadlessService)
Update: Headless JS support has now been integrated into the Premium version. It will arrive here after some testing and feedback.
What is "Headless JS"?
It's a mechanism to respond to any Background Geolocation event with your own custom Javascript, even after your app has been terminated.
BackgroundGeolocation Headless JS Support is now available in this Free Version.
Unfortunately, I haven't documented it much yet but it's really simple to setup.
NOTE: The HeadlessService runs only when the app is terminated.
AndroidManifest.xml<application>
<receiver android:name="com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationEventReceiver">
<intent-filter>
<!-- You may choose to listen to any, all or none of the following events. If you don't wish to listen to a particular event, remove it from your AndroidManifest -->
<action android:name="com.transistorsoft.locationmanager.event.BOOT" />
<action android:name="com.transistorsoft.locationmanager.event.TERMINATE" />
<action android:name="com.transistorsoft.locationmanager.event.HEARTBEAT" />
<action android:name="com.transistorsoft.locationmanager.event.MOTIONCHANGE" />
<action android:name="com.transistorsoft.locationmanager.event.LOCATION" />
<action android:name="com.transistorsoft.locationmanager.event.GEOFENCE" />
<action android:name="com.transistorsoft.locationmanager.event.HTTP" />
<action android:name="com.transistorsoft.locationmanager.event.SCHEDULE" />
<action android:name="com.transistorsoft.locationmanager.event.ACTIVITYCHANGE" />
<action android:name="com.transistorsoft.locationmanager.event.PROVIDERCHANGE" />
<action android:name="com.transistorsoft.locationmanager.event.GEOFENCESCHANGE" />
</intent-filter>
</receiver>
</application>
index.android.js, register your Headless Service:// First define or import your Service:
const BackgroundGeolocationHeadlessService = async (event) => {
// do stuff
console.log('[js] BackgroundGeolocationHeadlessService: ', event);
switch (event.name) {
case 'boot':
break;
case 'terminate':
break;
case 'heartbeat':
break;
case 'motionchange':
break;
case 'location':
break;
case 'geofence':
break;
case 'http':
break;
case 'schedule':
break;
case 'activitychange':
break;
case 'providerchange':
break;
case 'geofenceschange':
break;
}
};
// Now register it:
AppRegistry.registerHeadlessTask('BackgroundGeolocation', () => BackgroundGeolocationHeadlessService);
Most helpful comment
BackgroundGeolocation Headless JS Support is now available in this Free Version.
Unfortunately, I haven't documented it much yet but it's really simple to setup.
NOTE: The
HeadlessServiceruns only when the app is terminated.AndroidManifest.xmlindex.android.js, register your Headless Service: