Is it possible to get the location from NETWORK if GPS is OFF ?
My Demo can get the current user-location from NETWORK and from GPS but only if GPS is ON.
If I try to get the location from LastKnownLocation, I get null too.
@Override
protected void onResume() {
super.onResume();
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
startActivity(new Intent(MainActivity.this, Permissions.class));
return;
}
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
isGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPS && !isNetwork) {
Log.d("TAG", "gps and network false");
}else {
if (isGPS) {
loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (loc != null) {
Log.i("TAG", "gps loc found");}
}
if (isNetwork) {
loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (loc != null) {
Log.i("TAG", "network loc found");
}
}
I have tested this code below. it returns the location null too, if I make the device-gps off : GPSTracker.java