title: How to switch provider into GPS_provider if android phone doesn't have internet connection?
body: <p>i make a location application on android. here's the code for acquiring lat and long value.</p>
  
  <pre><code>public void geoLocation()
      {
          locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
          locationListener = new LocationListener() {
  
              public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location provider.
                  updateWithNewLocation(location);
              }
              public void onStatusChanged(String provider, int status, Bundle extras) {}
              public void onProviderEnabled(String provider) {
                  Toast.makeText(ListenSMSservice.this,"Network Enabled",Toast.LENGTH_SHORT ).show(); 
              }
              public void onProviderDisabled(String provider) {
                  Toast.makeText(ListenSMSservice.this,"Network Disabled",Toast.LENGTH_SHORT ).show();
              }
            };
          // Register the listener with the Location Manager to receive location updates
          locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
      }
  
      public void updateWithNewLocation(Location location) //update posisi terkini
      {
          if (location != null) {
              lat = location.getLatitude();
              lng = location.getLongitude();
  
              Geocoder gc = new Geocoder(ListenSMSservice.this, Locale.getDefault());
              try {
                List&lt;Address&gt; addresses = gc.getFromLocation(lat, lng, 1);
                StringBuilder sb = new StringBuilder();
                if (addresses.size() &gt; 0) {
                  Address address = addresses.get(0);
  
                  for (int i = 0; i &lt; address.getMaxAddressLineIndex(); i++)
                    sb.append(address.getAddressLine(i)).append("\n");
  
                    sb.append(address.getLocality()).append("\n");
                    sb.append(address.getCountryName());
                }
                addressString = sb.toString();
              } catch (IOException e) {}
  
              //latLongString = "Lat:" + lat + "\nLong:" + lng;     
              latLongUrl="Phone Map\nhttp://maps.google.com/maps?q=" + lat + ",+" + lng + "+(Your+phone+location)&amp;iwloc=A&amp;hl=en\n";
            } else {
              latLongUrl = "No location found"; 
            }
            myMessage=latLongUrl+"\n"+addressString;
            locationManager.removeUpdates(locationListener); 
            locationManager = null;
            //Toast.makeText(ListenSMSservice.this, myMessage, 3).show();
            sendsms();
      }
  </code></pre>
  
  <p>that code will works if i have an internet connection (<code>NETWORK_PROVIDER</code>). has anyone know how to modify that code for automatically switch into <code>GPS_PROVIDER</code> when android phone doesn't have any internet connection?? thanks</p>