@ RequiresPermission ( anyOf = { Manifest . permission . ACCESS_COARSE_LOCATION , Manifest . permission . ACCESS_FINE_LOCATION } ) public synchronized void startLocalization ( ) { if ( ! started && hasSignificantlyOlderLocation ( ) ) { started = true ; // get all enabled providers List < String > enabledProviders = locationManager . getProviders ( true ) ; boolean gpsProviderEnabled = enabledProviders != null && enabledProviders . contains ( LocationManager . GPS_PROVIDER ) ; boolean networkProviderEnabled = enabledProviders != null && enabledProviders . contains ( LocationManager . NETWORK_PROVIDER ) ; if ( gpsProviderEnabled || networkProviderEnabled ) { if ( gpsProviderEnabled ) { locationManager . requestLocationUpdates ( LocationManager . GPS_PROVIDER , LOCATION_MIN_TIME , 0 , this ) ; } if ( networkProviderEnabled ) { locationManager . requestLocationUpdates ( LocationManager . NETWORK_PROVIDER , LOCATION_MIN_TIME , 0 , this ) ; } AlarmUtils . scheduleElapsedRealtimeAlarm ( SystemClock . elapsedRealtime ( ) + LOCATION_MAX_TIME , getCancelPendingIntent ( ) ) ; LOGGER . info ( "Localization started" ) ; } else { started = false ; LOGGER . info ( "All providers disabled" ) ; } } }
Register the listener with the Location Manager to receive location updates