-
Notifications
You must be signed in to change notification settings - Fork 569
Closed
Labels
staleauto labeled abandoned issues after a period of inactivityauto labeled abandoned issues after a period of inactivity
Description
Can't watch for 'activity' event both when setting the listener or analysing the log. On iOS I get them normally using the same code.
Your Environment
numeric version changes over the time -->
- Plugin version: 0.5.0-alpha-24
- Platform: Android
- OS version: 8.0, 8.1
- Device manufacturer and model: Android simulator, Samsung Galaxy S8, Sony XA1
- React Native version: 0.55.4
- Plugin configuration options:
{
activitiesInterval: 5000,
activityType: 'Fitness',
desiredAccuracy: BackgroundGeolocation.MEDIUM_ACCURACY,
distanceFilter: 10,
debug: false,
fastestInterval: 1000,
interval: 60000,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
maxLocations: 100000,
notificationText: '',
notificationTitle: 'Fitness activity tracking enabled',
saveBatteryOnBackground: false,
startForeground: false,
startOnBoot: true,
stationaryRadius: 4,
stopOnTerminate: false,
stopOnStillActivity: false,
}Context
The following code is used:
getHistoricalData(new Date())
BackgroundGeolocation.events.forEach((event: string) => BackgroundGeolocation.removeAllListeners(event))
ListenGeolocationEvent('error')
ListenGeolocationEvent('activity')
ListenGeolocationEvent('location')
ListenGeolocationEvent('stationary')
BackgroundGeolocation.start()
const ListenGeolocationEvent = (event: string) => BackgroundGeolocation.on(event, (props: any) => {
BackgroundGeolocation.startTask((taskKey: string) => {
eventHandlers[event](props)
BackgroundGeolocation.endTask(taskKey)
})
})
const eventHandlers: any = {
activity: (activity: any) => activityHandler({sorted: [activity]}, new Date()),
...
}
function activityHandler({sorted}: {sorted: any}, timeStamp: Date = new Date()): void {
console.debug(timeStamp, 'activityHandler()', sorted)
...
}
function getHistoricalData(timeStamp: Date) {
BackgroundGeolocation.getLogEntries(
1000000, 0, 'TRACE',
(logs: any[] = []) => {
const stats: any = {
activity: 0,
location: 0,
stationary: 0,
}
logs.forEach((log: any) => {
const {message}: {message: string} = log
if(!message) return
let processed = false
if(message.startsWith('BgGeo #onActivityChanged')) {
stats.activity++
processed = true
}
if(message.startsWith('New location') || message.startsWith('BgGeo #onLocationChanged')) {
stats.location++
processed = true
}
if(message.startsWith('BgGeo #onStationaryChanged')) {
stats.stationary++
processed = true
}
if(message.startsWith('Location change')
|| message.startsWith('ActivityLocationProvider')
|| message.startsWith('Received MSG_ON_LOCATION')
|| message.startsWith('Service configured')
|| message.startsWith('BgGeo #configure')
|| message.startsWith('Will start')
|| message.startsWith('HeadlessTaskRunner')
|| message.startsWith('Running headless')
) {
processed = true
}
if(!processed) stats[message] = (stats[message] || 0) + 1
})
console.log(timeStamp, 'getHistoricalData/getLogEntries() ', {count: logs.length, stats})
},
(e: any) => console.warn(timeStamp, 'getHistoricalData/getLogEntries() Failed', e),
)
}Expected Behavior
I expect to have event handler called at least sometimes and have respective records in the log.
Actual Behavior
Handler is never called. Log stats have the following (this is from the simulator, but on real device this is similar):
getHistoricalData/getLogEntries(), {
count: 5410,
stats: {
"All clients have been unbound from service": 67,
"App will be paused": 67,
"App will be resumed": 71,
"Attempt to start bg service": 50,
"Attempt to start unconfigured service. Will use stored or default.": 1,
"Attempt to stop bg service": 50,
"Binding to service": 71,
"Client binds to service": 18,
"Client rebinds to service": 53,
"Connected to Google Play Services": 48,
"Connecting to Google Play Services": 48,
"Continue running in background": 26,
"Creating ActivityRecognitionLocationProvider": 48,
"Creating LocationService": 18,
"Destroying LocationService": 12,
"Destroying plugin": 48
"Initializing plugin": 70,
"Network condition changed has connectivity: true": 18,
"Received MSG_ON_SERVICE_STARTED": 724,
"Received MSG_ON_SERVICE_STOPPED": 710,
"Service connected": 71,
"Service started": 48,
"Start recording": 147,
"Start tracking with priority=102 fastestInterval=1000 interval=60000 activitiesInterval=5000 stopOnStillActivity=false": 99,
"Starting service": 50,
"Stop recording": 143,
"Stopping service": 50,
"Task has been removed": 26,
"Unbinding from service": 67,
"User granted requested permissions": 50,
activity: 0,
location: 147,
stationary: 0
}
}Steps to Reproduce
Use the code above (TypeScript)
Context
If I had the activity event records in the journal it would allow me get rid of the other 3rd party activity recognition module and disable background event listening. On iOS I process the BackgroundGeolocation journal when app goes foreground, it saves battery a lot.
RikNieuwoudt and Mattimus333
Metadata
Metadata
Assignees
Labels
staleauto labeled abandoned issues after a period of inactivityauto labeled abandoned issues after a period of inactivity