I am developing an application that I want to learn about the count of gps satellites. I am using the "onSatelliteStatusChanged" method for this, but it does not work. The piece of code that I use below that you see.
Code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
gnssStatusCallBack = new GnssStatus.Callback() {
@Override
public void onSatelliteStatusChanged(GnssStatus status) {
satelliteCount = status.getSatelliteCount();
}
};
locManager.registerGnssStatusCallback(gnssStatusCallBack);
} else {
locManager.addGpsStatusListener(this);
}
}
Note: I tested it outside.
Overview (request location updates to receive them):
Without explicitly asking for location updates, your device may not be seeking this information. The following worked for me where member
mGnssStatusCallback
is your GnssStatus.Callback and the Activity (or some other class) implements LocationListener; here this activity implements it and I passthis
as the final parameter torequestLocationUpdates
andremoveUpdates
. The30000
indicates that we're requesting updates every 30 seconds (30000 milliseconds), with0
indicating that we only want an update if the device has moved > 0 meters.You probably need to figure out what providers are available, etc.
see Android Training.
Example