How to get the number of satellites for Xamarin Android project

Viewed 135

I am working on the Xamarin Android project and I need to get the information of how many satellites (not accuracy and other workarounds). I found a solution below, however, the GpsStatus.IListener is obsoleted. Android Xamarin C#: Get the number of satellites used for GPS location I also tried FusedLocationProviderClient, but I couldn't see satellites information gets returned. Does anyone know how to solve the problem? Even a third party library helps. Thanks!

1 Answers

You could use GnssStatus instead.

GnssStatus: https://docs.microsoft.com/en-us/dotnet/api/android.locations.gnssstatus?view=xamarin-android-sdk-12

Add the code below in OnCreate method:

 LocationManager mLocationManager = (LocationManager)GetSystemService(Context.LocationService);
        mLocationManager.RegisterGnssStatusCallback(new GetSatellites()); 

GnssStatus.Callback:

 public class GetSatellites : GnssStatus.Callback
{
    public int satelliteCount;
    public override void OnSatelliteStatusChanged(GnssStatus status)
    {
        base.OnSatelliteStatusChanged(status);
        satelliteCount = status.SatelliteCount;
        Console.WriteLine("--------------------------"+satelliteCount);
    }
}

Do not forget to add the permission.

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
Related