Location service onProviderEnabled never called

后端 未结 1 863
忘了有多久
忘了有多久 2021-01-15 21:21

I have a service to update location in my app. When I start my app with GPS disable, go back to android menu and enable GPS, and finally go back to my app (the service has n

相关标签:
1条回答
  • 2021-01-15 22:08

    In your LocationService.onCreate() method your code checks if the GPS provider is disabled.

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){...}
    

    But you only start the subscription if it is already enabled. Note that your listener is then never registered with the LocationManager and will not receive any updates of location providers being disabled or enabled. Rather change your onCreate() method to always call

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5 * 60 * 1000, 100, this);
    
    0 讨论(0)
提交回复
热议问题