Forum Xamarin Xamarin.Android

Xamarin Android Location Manager RegisterGnssStatusCallback

_DK__DK_ DEMember ✭✭

Hi,

LocationManager.AddGpsStatusListener(GpsStatus.Listener listener) was deprecated in API level 24. You have to use registerGnssStatusCallback(GnssStatus.Callback) instead.

Has anyone an example code for this?

Posts

  • ScottDavisScottDavis USMember ✭✭

    DK did you find an example?

  • GuillaumeMARTINGuillaumeMARTIN FRMember

    You have to inherit the GnssStatus.Callback, then register your custom class.

    public class GnssStatusCallback : GnssStatus.Callback {
    public override void OnStarted()
    {
    base.OnStarted();
    }
    public override void OnStopped()
    {
    base.OnStopped();
    }
    public override void OnSatelliteStatusChanged(GnssStatus status)
    {
    base.OnSatelliteStatusChanged(status);
    }
    public override void OnFirstFix(int ttffMillis)
    {
    base.OnFirstFix(ttffMillis);
    }
    }

    Then
    this.locationManager = (LocationManager)this.context.GetSystemService(Context.LocationService);
    GnssStatusCallback gnssStatusCallback = new GnssStatusCallback();
    this.locationManager.RegisterGnssStatusCallback(gnssStatusCallback);

    Sorry for the code style, didn't make it work

  • _DK__DK_ DEMember ✭✭

    thanks Martin for your reply.
    I have tried your code but i get an error: "Java.Lang.NoClassDefFoundError "

    here:

    GnssStatusCallback gnssStatusCallback = new GnssStatusCallback(); //<===== Java.Lang.NoClassDefFoundError

    Do you have any idea why this happens?

  • mtimmermmtimmerm USMember ✭✭

    Same here :(

  • _DK__DK_ DEMember ✭✭

    GnssStatusCallback is only for API Level 24 and higher!
    If your app support API-Level 23 and lower than you have to check the API-Level:

         if ((int)Build.VERSION.SdkInt >= 24)
        {
            RegisterGnssStatusCallback …
        }else{
               
    LocationManager.AddGpsStatusListener(GpsStatus.Listener listener) …
        } 
    
Sign In or Register to comment.