I am using android studio 3.0 and the emulator with android 8.0 and 6.0 to get the location using the gps of the device.
Problem: I get the location from the emulator, the corresponding onLocationChanged method is activated, but every 10 seconds this method is executed again without having changed the position in the emulator.
I imagine that my location is deleted and it takes the same position again as a new location every 10 seconds and therefore I have an infinite cycle running every 10 seconds
Is this behavior correct in this method?
public void GPS() {
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
latitud = String.valueOf(location.getLatitude());
longitud = String.valueOf(location.getLongitude());
System.out.println("................"+latitud+ " ; " +longitud);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ) {
System.out.println("...........no hay permiso");
return;
}
System.out.println(".............todo ok");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}