Reputation: 81
I am developing a tracking app using fused location api. I want to check programatically if user has turned off location services while app is running.
I am thinking of running a parallel thread to check if GPS has been turned off by user in every 5 sec using method LocationManager.isProviderEnabled()
.
Is this the right approach or there is a better way to do it?
Upvotes: 3
Views: 676
Reputation: 991
Use broadcast receiver, when GPS settings will be changed, you will get automatically notified.
here is the link:
https://developer.android.com/training/monitoring-device-state/manifest-receivers.html
Upvotes: 2
Reputation: 14572
From the LocationListener documentation
abstract void onProviderEnabled(String provider)
Called when the provider is enabled by the user.abstract void onProviderDisabled(String provider)
Called when the provider is disabled by the user.
So you could use those event to know if the provider you are using to listening the position is enable / disabled.
Upvotes: 1