Shiny.net with MAUI.net not getting locations

96 views Asked by At

I am having trouble getting location tracking working with shiny.net. I can do it in foreground, but setting it up to send location data to a delegate is not working.

I am importing the relevant packages

<PackageReference Include="Shiny.Locations" version="3.2.3" />
<PackageReference Include="Shiny.Hosting.Maui" version="3.2.3" />

I am "using" shiny by adding UseShiny() to the mauibuilder.

Then I set the gps handler as

builder.Services.AddGps<CloudDash.Pages.Settings.MyGpsDelegate>(); 

I have a shell page taking an IGpsManager constructor argument, and though dependency injection, it does receive it as expected.

Then I try listening

await gpsManager.StartListener(new GpsRequest(GpsBackgroundMode.Standard));

but that throws an exception, telling me there is already a listener. I then try stopping that before starting again... just in case. I also tried not starting it myself and relying on what was supposedly already started (not by me).

await gpsManager.StopListener();

That seems to run ok, and I can see there is a current listener in the manager after starting listening again.

My delegate, that I registered earlier is not getting called, though. It is based on the delegate used in the sample code, since the one defined on the shiny-webpage introduction is apparently obsolete and cannot compile.

public partial class MyGpsDelegate : GpsDelegate
{
    public MyGpsDelegate(ILogger<MyGpsDelegate> logger) : base(logger)
    {
        this.MinimumDistance = Shiny.Distance.FromMeters(1);
        this.MinimumTime = TimeSpan.FromSeconds(1);
    }

    protected override Task OnGpsReading(GpsReading reading)
    {
        return Task.CompletedTask; //breakpoint
    }
}

On the android side, this partial bit of the class is written as

public partial class MyGpsDelegate : Shiny.IAndroidForegroundServiceDelegate
{
    public void Configure(NotificationCompat.Builder builder)
    {
        builder
                        .SetContentTitle("MyApp")
                        .SetContentText("My App is following you!! images")
                        .SetSmallIcon(Resource.Mipmap.appicon);
    }
}

According to what I could dig out of the sample code, and web site, this should be it. UseShiny, AddGps<T> and StartListening. Permissions are given for always location as well as notifications.

What am I missing?

0

There are 0 answers