Search code examples
androidgoogle-mapsgps

Gps On App only works after Using Google Maps


We have this android app that uses the maps api. Now when we run it, it usually doesn't work, when we call

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
100, 0, this, null);

It doesn't really work, the LocationListener's onLocationChanged method is never called. However, if we run Google Maps and wait until the gps icon is on in the status bar, then our app does start calling onLocationChanged. So my question is, how is Google Maps "activating" gps, or if they're not activating it, what are they doing?


Solution

  • You need to turn on GPS first:

    try {
      Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);
    } catch (Exception e) {
      logger.log(Log.ERROR, e, e.getMessage());
    }
    

    To do that, you also need to have permission from end-user i believe.