Detect or prevent if user uses fake location

前端 未结 4 2198
生来不讨喜
生来不讨喜 2020-12-14 02:39

I will block a user from using my app if they fake the location. So I use isFromMockProvider to check if the location is fake (follow here). But isFromMo

4条回答
  •  心在旅途
    2020-12-14 03:13

    Answers on This SO question and to a lesser extent the answers on This SO question seem to indicate you are suffering from an unfortunate Caching issue in the FusedLocationApi caused by onLocationChanged being called with an out of date timestamp (thus ignoring the result as it thinks there is already newer data).

    To quote Reno's answer:

    Unless you have not changed ... so that new APs can be discovered, I'm afraid you will get only cached locations. If you want fresh locations use the GPS provider.

    The solution will be to instead call a location from the GPS Provider like so:

    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
    

    (The code above comes from a longer example here)

提交回复
热议问题