i create an apps which doesn't let user using fake GPS, everything was smooth until i try close fake gps and turn off the mock location the message showing is still coordinate that i set in FakeGps App, how can i update the location of the Gps Location
private val LOCATION_PERMISSION_REQ_CODE = 1000;
private lateinit var fusedLocationClient: FusedLocationProviderClient
private var latitude: Double = 0.0
private var longitude: Double = 0.0
heres the function to detect Fake GPS
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
private fun getCurrentLocation() {
// checking location permission
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// request permission
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_BACKGROUND_LOCATION), LOCATION_PERMISSION_REQ_CODE);
return
}
fusedLocationClient.lastLocation
.addOnSuccessListener { location ->
// getting the last known or current location
latitude = location.latitude
longitude = location.longitude
Timber.tag("Data").e("Latlang" + latitude + longitude)
if (location.isFromMockProvider){
Timber.tag("FakeGPS").e("DETECT")
}else{
Timber.tag("FakeGPS").e("Not Detect")
}
}
.addOnFailureListener {
Toast.makeText(this, "Failed on getting current location",
Toast.LENGTH_SHORT).show()
}
}
thank you