title: Finding out how my location is being gathered. Force close on Location.getProvider();
body: <p>I need to check where my GPS service is getting the provider from, when GPS is off. I have it set up to Go GPS>network>Default which I assume is wifi. </p>
  
  <p>A little while ago when I set the location setting on my Nexus 5 to battery saving, it couldn't find my location at all in Google maps or my app. Even though it clearly says for Network/Wifi. I have since changed it back to High Accuracy, still a force close.</p>
  
  <p>Anyway does anyone know how I can find out where my location is coming from, either GPS, network or Wifi? First off the phone doesn't have a network (no sim card) so that's out.</p>
  
  <p>I keep getting a force close when trying to do location.getProvider(); I assume that's because it is returning null. Locat below.</p>
  
  <pre><code>if (LocationManager.GPS_PROVIDER.equals(location.getProvider())) {
              Log.i("TAG", "GPS");    
          } else if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) {
              Log.i("TAG", "NETWORK");
          }
          else {
              Log.i("TAG", "NEITHER");
  }
  
  02-24 17:26:27.016: E/AndroidRuntime(3395): Process: com.package.name, PID: 3395
  02-24 17:26:27.016: E/AndroidRuntime(3395): java.lang.NullPointerException
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at com.package.name.MapsPage$runGet.onPostExecute(MapsPage.java:535)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at com.package.name.MapsPage$runGet.onPostExecute(MapsPage.java:1)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.os.AsyncTask.finish(AsyncTask.java:632)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.os.Handler.dispatchMessage(Handler.java:102)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.os.Looper.loop(Looper.java:136)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at android.app.ActivityThread.main(ActivityThread.java:5017)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at java.lang.reflect.Method.invoke(Method.java:515)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  02-24 17:26:27.016: E/AndroidRuntime(3395):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>As you can see I'm running it in the onPostExecute of a server call as the very first thing. </p>
  
  <p>Anyone have any ideas? Is there a better way to call it possibly? I'm initiating the GPS finder as a service, if it fails it looks for a network, if it fails that goes to Wifi (Or at least I presume); The logcat barely provides me with any information.</p>
  
  <p>Would really appreciate some help on this, thanks!</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>public class MapsPage extends Fragment implements LocationListener {
      @Override
  public void onLocationChanged(Location location) {
  }
  
  public void onProviderDisabled(String provider) {
      Log.d("TAG", "onProviderDisabled: " + provider);
  }
  
  public void onProviderEnabled(String provider) {
      Log.d("TAG", "onProviderEnabled: " + provider);
  }
  
  public void onStatusChanged(String provider, int status, Bundle extras) {
      Log.d("TAG", "onStatusChanged: " + provider);
  }
  
  /*LocationListener[] mLocationListeners = new LocationListener[] {
          new LocationListener(LocationManager.GPS_PROVIDER),
          new LocationListener(LocationManager.NETWORK_PROVIDER)
  };*/
  }
  </code></pre>
  
  <p>Commented out the the bit below because of the error I was getting.</p>