Just complementing the @ramaral response !
Implementation of 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());
}
}
}
Implementation of 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());
}
}
Called as version:
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());
}
Perfect! Thank you very much!
– Thiago Luiz Domacoski