Apenas complementando a resposta do @ramaral !
Implementação do GpsStatus.Listener
:
class GPSStatusCallBack implements GpsStatus.Listener {
@Override
public void onGpsStatusChanged(int event) {
if (ActivityCompat.checkSelfPermission(Servico.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
GpsStatus gpsStatus = locationManager.getGpsStatus(null);
Iterator<GpsSatellite> satellites = gpsStatus.getSatellites().iterator();
while (satellites.hasNext()){
final GpsSatellite satellite = satellites.next();
final StringBuilder buff = new StringBuilder("");
buff.append("\nAzimuth: "+satellite.getAzimuth());
buff.append("\nElevation: "+satellite.getElevation());
buff.append("\nPRN: "+satellite.getPrn());
buff.append("\nSNR: "+satellite.getSnr());
Log.w(TAG, buff.toString());
}
}
}
Implementação do GnssStatus.Callback
:
@RequiresApi(api = Build.VERSION_CODES.N)
class GnssStatusCallback extends GnssStatus.Callback{
@Override
public void onSatelliteStatusChanged(GnssStatus status) {
int count = status.getSatelliteCount();
Log.w(TAG, "Quantidade de satelites: "+count);
for(int i = 0; i<count; i++){
final StringBuilder buff = new StringBuilder("");
buff.append("\nAzimuthDegrees: "+status.getAzimuthDegrees(i));
buff.append("\nConstellationType: "+status.getConstellationType(i));
buff.append("\nCn0DbHz: "+status.getCn0DbHz(i));
buff.append("\nElevationDegrees: "+status.getElevationDegrees(i));
buff.append("\nSvid: "+status.getSvid(i));
Log.w(TAG, buff.toString());
}
}
Chamado conforme versão:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locationManager.registerGnssStatusCallback(new GnssStatusCallback());
}else{
locationManager.addGpsStatusListener(new GPSStatusCallBack());
}