I am using location to implement geofencing functionality (limiting app usage to one country) In first activity in application I am using FusedLocationProviderClient to get location like this:
Init part
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
and location part
fusedLocationClient.getLastLocation().addOnSuccessListener(this, location -> {
if (location != null) {
//geofencing logic
}
});
This code works fine if location is enabled all the time on device. If user disables location in quick menu on top of phone or in settings and tries to enter app, it gets message that location is disabled and exits. After that if user tries to turn on location and enter app FusedLocationClient gets stuck and doesn't return location at all. After that it will only work if I reinstall application. Has anyone had this problem and tried to fix it other than using background location all the time with periodic updates?
PS Same thing happens if I try to use LocationService directly to access last known location.