0

I've written an android application that needs the user location, it was working fine when I used gps provider, but I don't want to use GPS because it uses a lot of battery, here is my code

LocationManager locaionManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,5*1000,0, new MyLocaionListener());
Location loco = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Log.d("enabled=" ,"" + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));

This code returns a null Location Object, and the logCat shows enabled=false when the location service is disabled although I'm using NETWORK_PROVIDER But when I enable the location service from the phone settings I get enabled=true and I get my current location.
So my question is: does network provider also uses the phone GPS? and how do GPS and NETWORK providers internally works.

monim
  • 3,427
  • 3
  • 23
  • 36
  • possible duplicate of http://stackoverflow.com/questions/13594932/network-provider-not-providing-updated-locations – Zahan Safallwa Oct 01 '15 at 15:14
  • Have you considered using the FusedLocationProvider available in Google Play Services? It should allow you the more effectively balance accuracy and battery use without significant logic on your end. – NasaGeek Oct 01 '15 at 15:16
  • @NasaGeek does it need to enable gps?? – monim Oct 03 '15 at 08:30

0 Answers0