I am trying to detect Mock Location. I have installed Fake location app and enabled Mock Locations in Settings (Under Developer Options). But when I try to detect Mock location using Geolocator, it doesn't work at all.
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission != LocationPermission.whileInUse &&
permission != LocationPermission.always) {
return Future.error(
'Location permissions are denied (actual value: $permission).');
}
}
return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
And then I call this function as:
_determinePosition().then((position) {
if (position.isMocked) {
//.. Show error message
return;
}
And this if block is never reached and there is no error log either.