I don't know why, but my varaiable isNetowrkEnabled
always return true. It doesn't matter if internet on my device is enabled or no.
This is my GPSTracker
class:
public class GPSTracker extends Service implements LocationListener{
private final Context mContext;
boolean isNetworkEnabled = false;
boolean canGetLocation = false;
Location location; // location
protected LocationManager locationManager;
public GPSTracker(Context context) {
this.mContext = context;
getLocation();
}
public Location getLocation() {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
System.out.println("Network enabled");
} else {
System.out.println("Network disabled");
}
}
}
Do you know what may be wrong in this code?