For Cuterdio 2.2 I added AppActions to the icon. I think it’s a great way to start, because you can choose your station directly:

With the great Xamarin.Essentials Update 1.6, we have an easy and straight forward way to add this actions. Let me show you my implementation 🦄.

iOS: Only four actions are possible

We simple add this code to our App.xaml.cs:

AppActions.OnAppAction += AppActions_OnAppAction;
private void AppActions_OnAppAction(object sender, AppActionEventArgs e)
{
  // Don't handle events fired for old application instances
  // and cleanup the old instance's event handler
  if (Application.Current != this && Application.Current is App app)
  {
    AppActions.OnAppAction -= app.AppActions_OnAppAction;
    return;
  }
  Device.BeginInvokeOnMainThread(async () =>
  {
    await AppActionsManager.Execute(e.AppAction);
  });
}

For the platforms you have to add some boiler code, see here.

I wrote a simple wrapper class for handling the set & execution of the actions. In my case the streaming urls is the ID and the name of the radio station is the title.
In Set() we check the platform and can catch exception if the device don’t support the actions. We can also add icon, which are have to be stored in the platform projects resources:

AppActionsManager.Set(stations);
public static void Set(List<Station> stations)
{
  if (Device.RuntimePlatform != Device.iOS)
  {
    return;
  }

  try
  {
    List<AppAction> appActions = new List<AppAction>();
    foreach (var station in stations)
    {
      string id = station.Url;
      string title = station.Name;
      string subtitle = station.Description;
      string icon = "broadcast_tower";
      var appAction = new AppAction(id, title, subtitle, icon);
      appActions.Add(appAction);
    }
    AppActions.SetAsync(appActions);
  }
  catch (FeatureNotSupportedException) { }
}

 

If an action is executing, we now can get the Id and built up our business logic… For example, play a station:

public static async Task Execute(AppAction appAction)
{
  var url = appAction.Id;
  var stations = AppSettingsManager.LoadStations();
  var station = stations.FirstOrDefault(obj => obj.Url.Equals(url));
  if (station != null)
  {
    await App.PlayerPage.PlayStationAsync(station, true);
  }
}

 

I love Xamarin.Essentials and want to say a big THANK YOU to all contributors ❤️