Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackgoundGeolocation.on('location, ...) not being fired on android 8.1.0 #195

Closed
GillesVercammen opened this issue May 18, 2018 · 15 comments
Labels
discussion help wanted stale auto labeled abandoned issues after a period of inactivity

Comments

@GillesVercammen
Copy link

GillesVercammen commented May 18, 2018

"react-native": "0.53.3",
in my build.gradle:
ext {
compileSdkVersion = 26
targetSdkVersion = 26
buildToolsVersion = "26.0.2"
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "11.8.0"
oreoEXPERIMENTAL = "yes"
}

  • Plugin version: v0.5.0-alpha.25
  • Platform: Android
  • OS version: 8.1.0 Oreo
  • Device manufacturer and model: Nexus 5
  • React Native version: 0.53.3
  • Plugin configuration options:
    ext {
    compileSdkVersion = 26
    targetSdkVersion = 26
    buildToolsVersion = "26.0.2"
    supportLibVersion = "26.1.0"
    googlePlayServicesVersion = "11.8.0"
    oreoEXPERIMENTAL = "yes"
    }
  • Link to your project: (private on bb)

Context

The backgroundlocation is being started after i press accept in the permission dialog, but it doesn't trigger the backgroundGeolocation.on('location', ...). I don't know if this is because there are no location received, or because it just doesn't trigger.
all relevant backgroundgeolocation code:
https://gist.github.com/GillesVercammen/aba915e6e53bd9abe5ba382f15c2742d

On ios it works like it should.

Expected Behavior

User logs in --> get asked for permission --> accepts --> background location is starting / tracking toggle on --> location gets updated, on location check distance --> if distance < 500, show alert

Actual Behavior

  1. The application ask for permission correctly, then when i press accept. The background location starts. i even get the notification that background location is enabled. The problem is that i never receive any locations, so i'm not getting into the BackgroundLocation.on('location') callback.

  2. The application is checking the status of the background tracking before the service has actually started. Relevant code:
    https://gist.github.com/GillesVercammen/77a4dd2c5e9ffffb497b5128891e137a

This is the order of function getting called in my debugged:
[INFO] App is in background
UserList.js:256 [NOTE] CHECKING THE TRACKING STATUS!!!
UserList.js:261 [NOTE] TRACKING IS NOT RUNNING
UserList.js:210 [INFO] App is in foreground
UserList.js:221 IN FOREGROUND AND STARTING
UserList.js:243 [NOTE] app is in handleAppstate and authorized, starting tracking!!!
UserList.js:250 HANDLE STATE AND STARTING
UserList.js:256 [NOTE] CHECKING THE TRACKING STATUS!!!
UserList.js:261 [NOTE] TRACKING IS NOT RUNNING
2UserList.js:186 [INFO] BackgroundGeolocation service has been started

As you can see it is checking station before the geolocation actually started running, which makes it so that my toggle is in 'off' modus, even though the app is tracking

Possible Fix

Steps to Reproduce

https://gist.github.com/GillesVercammen/aba915e6e53bd9abe5ba382f15c2742d

Context

I'm trying to track geolocation after permission was accepted on android.
Trying to track when app is in foreground and background. both not working

Debug logs

Relevant parts from printAndroidLogs or printIosLogs.
05-18 09:47:27.615 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.react.BackgroundGeolocationModule: App will be resumed
05-18 09:47:27.665 31552-32350/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Stopping service
05-18 09:47:27.688 31552-32351/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Starting service
05-18 09:47:27.695 31552-32353/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Stopping service
05-18 09:47:27.698 31552-32349/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.data.sqlite.SQLiteConfigurationDAO: Configuration persisted with rowId = 1
05-18 09:47:27.700 31552-32349/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Service configured with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=10000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=2 nTitle=Background tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate=null]
05-18 09:47:27.701 31552-32354/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Starting service
05-18 09:47:27.719 31552-32351/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.BackgroundGeolocationFacade: Starting bg service
05-18 09:47:27.765 31552-32354/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.BackgroundGeolocationFacade: Starting bg service
05-18 09:47:27.768 31552-32352/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.data.sqlite.SQLiteConfigurationDAO: Configuration persisted with rowId = 1
05-18 09:47:27.769 31552-32352/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Service configured with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=20000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=2 nTitle=Background tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate=null]
05-18 09:47:27.832 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.LocationService: Creating LocationService
05-18 09:47:27.920 31552-31552/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Binding to service
05-18 09:47:27.921 31552-32357/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.LocationService: Network condition changed has connectivity: true
05-18 09:47:27.941 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.LocationService: Received start command startId: 1 intent: Intent { flg=0x4 cmp=be.appfoundry.digitalreceptionist.debug/com.marianhello.bgloc.LocationService (has extras) }
05-18 09:47:28.043 31552-31552/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.LocationService: Will start service with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=20000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=2 nTitle=Background tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate={"altitude":"@altitude","provider":"@Provider","bearing":"@bearing","locationProvider":"@locationProvider","latitude":"@latitude","accuracy":"@accuracy","time":"@time","radius":"@radius","speed":"@speed","longitude":"@longitude"}]
05-18 09:47:28.060 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.provider.RawLocationProvider: Creating RawLocationProvider
05-18 09:47:28.080 31552-31552/be.appfoundry.digitalreceptionist.debug I/AudioTrack: AUDIO_OUTPUT_FLAG_FAST successful; frameCount 960 -> 960
05-18 09:47:28.080 31552-31552/be.appfoundry.digitalreceptionist.debug D/AudioTrack: Client defaulted notificationFrames to 192 for frameCount 960
05-18 09:47:28.094 31552-31552/be.appfoundry.digitalreceptionist.debug W/Notification: Use of stream types is deprecated for operations other than volume control
05-18 09:47:28.094 31552-31552/be.appfoundry.digitalreceptionist.debug W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
05-18 09:47:28.097 31552-31552/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.BackgroundGeolocationFacade: Binding to service
05-18 09:47:28.119 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.LocationService: Received start command startId: 2 intent: Intent { flg=0x4 cmp=be.appfoundry.digitalreceptionist.debug/com.marianhello.bgloc.LocationService (has extras) }
05-18 09:47:28.131 31552-31552/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.provider.RawLocationProvider: Destroying RawLocationProvider
05-18 09:47:28.147 31552-31552/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.LocationService: Will start service with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=20000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=2 nTitle=Background tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate={"altitude":"@altitude","provider":"@Provider","bearing":"@bearing","locationProvider":"@locationProvider","latitude":"@latitude","accuracy":"@accuracy","time":"@time","radius":"@radius","speed":"@speed","longitude":"@longitude"}]
05-18 09:47:28.161 31552-31552/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.provider.RawLocationProvider: Creating RawLocationProvider
05-18 09:47:28.174 31552-31552/be.appfoundry.digitalreceptionist.debug I/AudioTrack: AUDIO_OUTPUT_FLAG_FAST successful; frameCount 960 -> 960
05-18 09:47:28.174 31552-31552/be.appfoundry.digitalreceptionist.debug D/AudioTrack: Client defaulted notificationFrames to 192 for frameCount 960

EDIT:
updates plugin version

@mauron85
Copy link
Owner

v0.5.0-alpha.1 is too old. Please update your plugin and try to reproduce on latest version.

@GillesVercammen
Copy link
Author

GillesVercammen commented May 18, 2018

What is the newest version? When i look at releases, it says that v0.5.0-alpha.1 is last released version?

EDIT:
I found that my actual version is v0.5.0-alpha.25 in package.json
I assumed it was 0.5.0-alpha.1 because this was the latest in releases. my excuses.

Anyway. I upgraded to .27 and still have the problem @mauron85

@mauron85
Copy link
Owner

I see you're calling start on fg and bg events and some _handleAppStateChange method. Make sure it's actually called.

@GillesVercammen
Copy link
Author

I assume it is getting called because when i allow the permission and check the android logcat, it tells me that the service has started + it logs my console.log in the on('start', ..)
It's just not sending any actual locations.

i'm getting this in my android logcat:

05-18 11:34:34.504 4516-4516/be.appfoundry.digitalreceptionist.debug D/com.marianhello.bgloc.LocationService: Will start service with: Config[distanceFilter=50 stationaryRadius=50.0 desiredAccuracy=100 interval=20000 fastestInterval=5000 activitiesInterval=10000 isDebugging=true stopOnTerminate=false stopOnStillActivity=false startOnBoot=false startForeground=true locationProvider=2 nTitle=Background tracking nText=enabled nIconLarge= nIconSmall= nIconColor= url= syncUrl= syncThreshold=100 httpHeaders={} maxLocations=10000 postTemplate={"altitude":"@altitude","provider":"@Provider","bearing":"@bearing","locationProvider":"@locationProvider","latitude":"@latitude","accuracy":"@accuracy","time":"@time","radius":"@radius","speed":"@speed","longitude":"@longitude"}]

05-18 11:34:34.528 4516-4516/be.appfoundry.digitalreceptionist.debug I/com.marianhello.bgloc.provider.RawLocationProvider: Creating RawLocationProvider

@mauron85
Copy link
Owner

Check if on('start') is being called and also if location services are enabled

    BackgroundGeolocation.checkStatus(status => {
      console.log('[INFO] BackgroundGeolocation service is running', status.isRunning);
      console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
      console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

      // you don't need to check status before start (this is just the example)
      if (!status.isRunning) {
        BackgroundGeolocation.start(); //triggers start on start event
      }
    });

@GillesVercammen
Copy link
Author

The checkStatus method is getting called to early for me.
In my handleAppStateChange method:
i do BackgroundGeolocation.start() => takes some time
then i do checkStatus in the same handleAppStateChange method, but this gets called before the start() has finished. Maybe this is my problem

@juergengunz
Copy link

i have the same problems its not working with API 26 if i use 23 the location updates are working as expected.

@mauron85
Copy link
Owner

mauron85 commented May 31, 2018

This is unfortunate situation, which first appeared with Android Marshmallow. I really wish I can help here, but with my current hw (Nexus 4 on Lineage 15.1 (aka Oreo) I cannot replicate this.

Actually my experience is opposite to @juergengunz. With API 23 and Oreo with Activity Provider I've seen "App is using too much power" notification, but not in API 26.

But I saw that one fork is trying to turn off some battery optimisations (ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) Not sure if it help your issues. but definitively you can try to add something like that guy did.

mauron85/cordova-plugin-background-geolocation@master...pavelety:master

EDIT: My reference to Android Marshmallow is not relevant here. It's different issue people had reported in the past - no location updates in the background. This issue is about not receiving locations at all.

@mauron85
Copy link
Owner

mauron85 commented May 31, 2018

Also one more thing. All commenters please at least add "Device manufacturer and model" and "OS version" and "Plugin version" and used "Android API level" if different from original report.

@juergengunz
Copy link

juergengunz commented May 31, 2018

hope this helps:

I am using the latest RN 0.55
compileSdkVersion = 26
targetSdkVersion = 26
minSdkVersion 21
buildToolsVersion = "26.0.2"
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "11.8.0"
oreoEXPERIMENTAL = "yes"

Provider used: ACTIVITY_PROVIDER

Tested on latest Genymotion with
Google Nexus 5 6.0.0 - API 23 - not working
Samsung Galaxy S8 - 8.0 - API 26 - not working

Tested on real Device
LG G4c - 6.0.0 - working

Note:
I am using react-native-maps

Before I updated to API 26 and used the latest release of this project, I used API 23 and an older version of this project and it worked on both simulators & real devices.

I discovered a weird behavior in the simulators: If I use the settings above and execute BackgroundGeolocation.start(); it somehow breaks the simulators gps. If I open Google Maps on simulator to show the device location, it will not update the location anymore, even if I change it in the simulators... until I restart the simulator...

@rtiwarihr
Copy link

The callback is delayed on iOS.
#198

@stale
Copy link

stale bot commented Dec 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale auto labeled abandoned issues after a period of inactivity label Dec 13, 2018
@stale
Copy link

stale bot commented Dec 20, 2018

This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn't be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it's important. Thank you for your contributions.

@stale stale bot closed this as completed Dec 20, 2018
@smarttourist
Copy link

BackgroundGeolocation.on("location", location => {
//Send driver location to passenger
console.log(location)
this.socket.emit("driverLocation", {
latitude: this.state.latitude,
longitude: this.state.longitude
});

BackgroundGeolocation.on("authorization", status => {
console.log(
"[INFO] BackgroundGeolocation authorization status: " + status
);
if (status !== BackgroundGeolocation.AUTHORIZED) {
// we need to set delay or otherwise alert may not be shown
setTimeout(
() =>
Alert.alert(
"App requires location tracking permission",
"Would you like to open app settings?",
[
{
text: "Yes",
onPress: () => BackgroundGeolocation.showAppSettings()
},
{
text: "No",
onPress: () => console.log("No Pressed"),
style: "cancel"
}
]
),
1000
);
}
});
}

this. 2 functions are not working

@dipankurXT
Copy link

same issue please reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion help wanted stale auto labeled abandoned issues after a period of inactivity
Projects
None yet
Development

No branches or pull requests

6 participants