-1

we have developed C.R.M. software which provides location tracking functionality in background . to achieve that functionality i have used foreground service for android OREO or above version of android .

we are trying to get current location of user using LocationMangager and have attached onlocationchage listener . we are successfully getting data in service , and than storing those data in SQLite .

twist is that when we kill the application or put application in the background service runs fine but location manager doesn't gets longitude and latitude after a while may be 2 - 3 minutes . we also checked that . if service is running in the background or its getting killed but service is running in the background and printing log in the logcat. we have put CounteDownTimer to print log in LogCat . we also tried to keep application open , not killed , not even in background . it happens same , LocationManger was not getting latitude and longitude after a while . application was running in our phone on main screen .

here is the things we tried : -

  • i have tried GPS provider ( not working after a while )
  • i have tried Network provider ( not working after a while )
  • i have tried passive provider ( not working after a while )
  • i have tried google fused location but it is not even getting location data .
  • i have put WakeLock in service so that CPU does not go into idle mode (tried partial and full wake lock)

Note : -

  • i am demanding location for given interval and for given distance . i have tried in our office and also out side of office but we are not getting data after a while . i am sure that given distance is getting covered .

thank you in advance and i can not show my code reason is that our company does not allow to post Company code in any platform . sorry .....

1 Answers1

2

You'll need to run the service in the foreground. As part of that, you'll need to request the permission in your manifest, along with a couple of others things. I followed this example recently to solve a similar issue.