I have a cross platform XF app.
I am using Toast.Forms for sending local app notifications, the plugin works on both iOS and Android. On iOS it works perfectly fine, but on Android it works only for versions lower than 7.1, for oreo 8.0 or 8.1 (> API 26) it does not work anymore.
Here is my toast class:
internal class ToastService : IToastService
{
private readonly IAppDeviceDependency _DeviceDependency;
public ToastService([NotNull] IAppDeviceDependency deviceDependency)
{
_DeviceDependency = deviceDependency ?? throw new ArgumentNullException(nameof(deviceDependency));
}
public void ShowToast(string title, string description, bool isClickable, bool clearFromHistory)
{
DeviceToastProvider.ShowToast(title, description, isClickable, clearFromHistory);
}
private IToastProvider DeviceToastProvider => _DeviceDependency.Get<IToastProvider>();
}
Android toast provider:
[assembly: Dependency(typeof(AndroidToastProvider))]
namespace MyApp.Droid.Providers
{
public class AndroidToastProvider : IToastProvider
{
public async void ShowToast(string title, string description, bool isClickable, bool clearFromHistory)
{
var notificator = DependencyService.Get<IToastNotificator>();
await notificator.Notify(new NotificationOptions
{
Title = title,
Description = description,
IsClickable = isClickable,
ClearFromHistory = clearFromHistory
});
}
}
}
Apple toast provider
[assembly: Dependency(typeof(AppleToastProvider))]
namespace MyApp.iOS.Providers
{
public class AppleToastProvider : IToastProvider
{
public async void ShowToast(string title, string description, bool isClickable, bool clearFromHistory)
{
var notificator = DependencyService.Get<IToastNotificator>();
await notificator.Notify(new NotificationOptions
{
Title = title,
Description = description,
IsClickable = isClickable,
ClearFromHistory = clearFromHistory
});
}
}
}
Found the solution to the problem. Apparently I was compiling using Android version 7.1, which does not support the newly Notification Channel of the Android Oreo 8.0. Now I am compiling using Android 8.1 (Oreo), I have updated Toast.plugin to the latest version and it works perfectly fine on all versions lowers than Android 8.1
More on the issue can be found here: https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/local-notifications