I'm trying to create a foreground service that can track the user's location with the phone's GPS. I have a ForegroundService
class, where in the onCreate()
method I call a function that should start by asking for location updates:
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
val locationListener: LocationListener = this
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 2000, 0F, locationListener
)
My class is implementing Service()
and LocationListener
. I then override onLocationChanged
, where I should log the current speed (and leave onAccuracyChanged
empty).
Of course I have a notification correctly showing in android, so the service is definitely running, but I seem to get no location updates anyways. What could the problem be? Thank you.
from Use onLocationChanged() updates inside a foreground service
No comments:
Post a Comment