use of android.location.LocationManager in project platform_frameworks_base by android.
the class TrackerService method initLocationListeners.
private synchronized void initLocationListeners() {
mTrackerData = new TrackerDataHelper(this);
LocationManager lm = getLocationManager();
mTrackedProviders = getTrackedProviders();
List<String> locationProviders = lm.getAllProviders();
mListeners = new ArrayList<LocationTrackingListener>(locationProviders.size());
long minUpdateTime = getLocationUpdateTime();
float minDistance = getLocationMinDistance();
for (String providerName : locationProviders) {
if (mTrackedProviders.contains(providerName)) {
Log.d(LOG_TAG, "Adding location listener for provider " + providerName);
if (doDebugLogging()) {
mTrackerData.writeEntry("init", String.format("start listening to %s : %d ms; %f meters", providerName, minUpdateTime, minDistance));
}
LocationTrackingListener listener = new LocationTrackingListener();
lm.requestLocationUpdates(providerName, minUpdateTime, minDistance, listener);
mListeners.add(listener);
}
}
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (doDebugLogging()) {
// register for cell location updates
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
// Register for Network (Wifi or Mobile) updates
mNetwork = new NetworkStateBroadcastReceiver();
IntentFilter mIntentFilter;
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
mIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
Log.d(LOG_TAG, "registering receiver");
registerReceiver(mNetwork, mIntentFilter);
}
if (trackSignalStrength()) {
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
// register for preference changes, so we can restart listeners on
// pref changes
mPrefListener = new PreferenceListener();
getPreferences().registerOnSharedPreferenceChangeListener(mPrefListener);
}
use of android.location.LocationManager in project platform_frameworks_base by android.
the class NetInitiatedActivity method sendUserResponse.
// Respond to NI Handler under GnssLocationProvider, 1 = accept, 2 = deny
private void sendUserResponse(int response) {
if (DEBUG)
Log.d(TAG, "sendUserResponse, response: " + response);
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.sendNiResponse(notificationId, response);
}
use of android.location.LocationManager in project carat by amplab.
the class Sampler method requestLocationUpdates.
private void requestLocationUpdates() {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
lm.removeUpdates(this);
List<String> providers = SamplingLibrary.getEnabledLocationProviders(context);
if (providers != null) {
for (String provider : providers) {
lm.requestLocationUpdates(provider, Constants.FRESHNESS_TIMEOUT, 0, this);
// Log.v(TAG, "Location updates requested for " + provider);
}
}
}
use of android.location.LocationManager in project carat by amplab.
the class SamplingLibrary method getBestProvider.
public static String getBestProvider(Context context) {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_COARSE);
c.setPowerRequirement(Criteria.POWER_LOW);
String provider = lm.getBestProvider(c, true);
return provider;
}
use of android.location.LocationManager in project carat by amplab.
the class SamplingLibrary method getLastKnownLocation.
private static Location getLastKnownLocation(Context context, String provider) {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location l = lm.getLastKnownLocation(provider);
return l;
}
Aggregations