List of usage examples for android.location LocationManager addGpsStatusListener
@Deprecated @RequiresPermission(ACCESS_FINE_LOCATION) public boolean addGpsStatusListener(GpsStatus.Listener listener)
From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java
public static void registerOnThread(Context context, LocationListener locationCallback, Listener listener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getAllProviders(); Log.i(TAG, "Found " + providers.size() + " location providers"); for (String provider : providers) { if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Provider " + provider + " enabled"); } else {//from w w w. ja va2 s . c om Log.i(TAG, "Provider " + provider + " disabled"); } } for (int pi = 0; pi < PROVIDERS.length; pi++) { String provider = PROVIDERS[pi]; if (locationManager.isProviderEnabled(provider)) { Log.i(TAG, "Registering with provider " + provider); Location loc = locationManager.getLastKnownLocation(provider); if (loc != null) { Log.i(TAG, "Last Location, provider=" + loc.getProvider() + ", lat=" + loc.getLatitude() + ", long=" + loc.getLongitude() + ", bearing=" + (loc.hasBearing() ? "" + loc.getBearing() : "NA") + ", speed=" + (loc.hasSpeed() ? "" + loc.getSpeed() : "NA") + ", accuracy=" + (loc.hasAccuracy() ? "" + loc.getAccuracy() : "NA") + ", alt=" + (loc.hasAltitude() ? "" + loc.getAltitude() : "NA")); ZoneService.updateLocation(context, loc); } //if (!"passive".equals(provider)) if (locationCallback != null) locationManager.requestLocationUpdates(provider, 0/*minTime*/, 0/*minDistance*/, locationCallback); } else Log.e(TAG, "Required provider " + provider + " not enabled!"); } if (listener != null) locationManager.addGpsStatusListener(listener); }
From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java
private void startActiveMode() { LocationManager lm = getLocationManager(); if (!isGpsAvailable(lm)) { return;/*from w w w. j a v a2 s. c om*/ } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, ACTIVE_MODE_GPS_MIN_UPDATE_TIME_MS, ACTIVE_MODE_GPS_MIN_UPDATE_DISTANCE_M, this); reportLocationLost(); mGPSListener = new GpsStatus.Listener() { public void onGpsStatusChanged(int event) { if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { GpsStatus status = getLocationManager().getGpsStatus(null); Iterable<GpsSatellite> sats = status.getSatellites(); int satellites = 0; int fixes = 0; for (GpsSatellite sat : sats) { satellites++; if (sat.usedInFix()) { fixes++; } } if (fixes < MIN_SAT_USED_IN_FIX) { reportLocationLost(); } } else if (event == GpsStatus.GPS_EVENT_STOPPED) { reportLocationLost(); } } }; lm.addGpsStatusListener(mGPSListener); }