OnProviderEnabled not working?

To switch between GPS and the network location provider, I just tried in such a way as to determine when the provider is disconnected, switch to another, but my onProviderEnabled() will not be called

 public void onProviderDisabled(String provider) { Toast.makeText(TrackerService.this, "Disabled : " + provider, Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String provider) { Toast.makeText(TrackerService.this, "Enabled : " + provider, Toast.LENGTH_LONG).show() 
+4
source share
1 answer

Define the location receiver as follows:

 LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { } public void onProviderDisabled(String provider) {} public void onProviderEnabled(String provider) {} public void onStatusChanged(String provider, int status, Bundle extras) {} }; 

Then:

 LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 
+3
source

Source: https://habr.com/ru/post/1388908/


All Articles