title: How can I check if GPS is enabled before I try to use it
body: <p>I have the following code and it's not good because sometimes GPS takes very long</p>
  
  <p>How can I do the following:</p>
  
  <ol>
  <li>Check if GPS is enabled</li>
  <li>Use GPS if it is enabled otherwise use the network provider.</li>
  <li>If GPS takes more than 30 seconds, use network.</li>
  </ol>
  
  <p>I can do this with my own logic using a time or Thread.sleep but I think there might be a more stabndard way</p>
  
  <pre><code>// Acquire a reference to the system Location Manager
              LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  
              // Define a listener that responds to location updates
              LocationListener locationListener = new LocationListener() {
                  public void onLocationChanged(Location location) {
                    // Called when a new location is found by the network location provider.
                      locationCallback(location);
                  }
  
                  public void onStatusChanged(String provider, int status, Bundle extras) {}
  
                  public void onProviderEnabled(String provider) {}
  
                  public void onProviderDisabled(String provider) {}
                };
  
              // Register the listener with the Location Manager to receive location updates
              locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
  </code></pre>