Search code examples
androidgpslocationmanager

GPS Notification "Location set by gps"


I wrote a simple gps tracker which collect gps information in a service

private void startListenCoordinateUpdates() {
    LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    String provider = LocationManager.GPS_PROVIDER;
    int updateTime = 2*1000, updateDistance = 10;

    locationManager.requestLocationUpdates(provider, updateTime, updateDistance, locationListener);
}

private void stopListenCoordinateUpdates() {
    LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationManager.removeUpdates(locationListener);
}

private class GpsTrackerLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location loc) {
         currentTrackInfo.addCoordinate(loc.getLatitude(), loc.getLongitude(), loc.getTime());
    }

    @Override 
    public void onProviderDisabled(String provider) { }

    @Override 
    public void onProviderEnabled(String provider) { }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) { }
}

but when first coordinate is received system notification with text "Location set by gps" and my app icon is raised. When I push it Location services settings appears. This notification then never disappear even if I remove listener or uninstall my app. I don't want to show it. How can I get rid of this notification??? I use android emulator and send gps coordinates via DDMS


Solution

  • Please check it on the real android device.. Usually to stop listening the updates from the GPS receiver I follow the following steps.

     1. locationManager.removeUpdates(locationListener);
     2. set locationListener = null
     3. set locationManager = null
    

    And make sure that you run the app on real device.