I got a problem when using LocationManager requestLocationUpdates
on Lollipop device. The LocationListener()
callback doesn't get called. Also I've tried to use FusedLocationProviderClient api, but also the callback doesn't work. (All dependency like permissions, Manifest, GPS are already ON)
This is my code for LocationManager
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d("test", "GOTCHA");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
});
This is for FusedLocationProviderClient
FusedLocationProviderClient fusedLocationProviderClient = new FusedLocationProviderClient(getContext());
LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Log.d("test", "GOTCHA");
if (locationResult != null) {
Location currentLocation = locationResult.getLastLocation();
handleCurrentLocation(currentLocation);
fusedLocationProviderClient.removeLocationUpdates(this);
} else {
failToGetLocationHandler("Fail to initiate request location ...");
}
}
};
fusedLocationProviderClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
I've tried to look every where for solutions but no luck for me. But the thing is, it works on other Android version like Nougat / Oreo. As far as I know, these 2 APIs don't have any problem with Lollipop (please CMIIW).
Thanks