Toast Notifications for Xamarin Forms

I manage the fairly popular Toasts.Forms.Plugin which displays toast like notifications on all platforms. This was originally created almost 2 years ago by EgorBo when the notification system on each platform was not very extensible or usable, hence you had to create your own if you wanted to display notifications while the app was in the foreground and have some respectable customization options. With iOS10, Android Lollipop and UWP there is now a decent notification system on each platform. Considering the new functionality, the Plugin has been rewritten to use each of native platforms notification systems.


Whats Changed

In version 3.0 a lot has changed including many breaking changes but its still easy to use.

#1 – Native Platform Notifications

While this has now limited the customization of the notification, it now brings the notifications inline with the platform look and feel and allows them to be placed in the notification center. To me this is much better than out of place notifications with its own style and now works more seamlessly with the platform and what the user is expecting. It also allows possibilities such as sound and badges.

#2 – More informative result

I have kept the flow of the API the same meaning you await for the response of the notification, but instead of just a Tapped response you receive a much better result as to what happened. You now receive a NotificationResult with an Action with one of these options.

 public enum NotificationAction
     Timeout = 1, // Hides by itself
     Clicked = 2, // User clicked on notification
     Dismissed = 4, // User manually dismissed notification
     ApplicationHidden = 8, // Application went to background
     Failed = 16 // When failed to display the toast

#3 – Options

You now pass through options instead of a large parameter list. This will enable future API enhancements to be made without breaking existing apps.

public interface INotificationOptions
    string Title { get; }
    string Description { get; }
    bool IsClickable { get; }

    // Platform Specific Options
    IWindowsOptions WindowsOptions { get; }
    IAndroidOptions AndroidOptions { get; }
    IiOSOptions iOSOptions { get; }

#4 – Override the Image

On UWP, Android (Notification.Builder only) and iOS you can override the logo image. On iOS it isn’t possible to replace the logo image via code but can be done in your info.plist.

The images work much like other components in Xamarin Forms, where you can just reference the name of the image and in UWP it will search the project root.

var options = new NotificationOptions() { WindowsOptions = new WindowsOptions { LogoUri = "image.png" } }

You can also add a url such as or do a platform specific url such as ms-appx://.

For Android you can set the SmallIconDrawable in the Init() method on the platform. The Image MUST be in the Drawables folder to work.

// This is called on the Android Platform
ToastNotification.Init(this, new PlatformOptions() { SmallIconDrawable = Android.Resource.Drawable.IcDialogInfo } );

Alternatively if you can pass this int value down into your PCL you can use this in AndroidOptions on a per toast notification.

Using The Plugin

After you have installed the plugin on each platform and your portable library, you will need to register and initialize it. Just after the Xamarin.Forms.Init(); line add the following. I am just using the DependencyService as an example, you can use any DI Framework.


// For Android pass through the activity

On iOS just after this, we need to request permissions to show notifications because as Apple correctly states, they are disruptive to the user and hence permission is just common courtesy.

// Request Permissions
                                                      | UNAuthorizationOptions.Badge 
                                                      | UNAuthorizationOptions.Sound, 
                                                      (granted, error) =>
                                                           // Do something if needed

Now we can call a notification anywhere in your app with the following.

var options = new NotificationOptions()
    Title = "Title",
    Description = "Some Description",
    IsClickable = false // Set to true if you want the result Clicked to come back (if the user clicks it)
var notification = DependencyService.Get<IToastNotificator>();
var result = await notification.Notify(options);

Future Roadmap

This is open source software being coded on in my spare time, hence I can never guarantee any enhancement schedules but here is the main focus for improvements.

  1. Customizable Action Buttons
  2. Callback Action on notification result (so you don’t have to await)
  3. Further customizable content
  4. Receive user input in from the notification


  1. Emre ERDEN

    Hi Adam, great work but I have an issue on Version 2.0.4. I want to know that how can I handle when toast notification clicked?

  2. Paul

    Hi Adam, is there a way to change the duration of the notification? It is currently set to a couple of seconds, but I need it longer, up to infinity (before it is clicked).

  3. Renjith

    I am getting this error when trying to install:
    Could not install package ‘Toasts.Forms.Plugin 3.2.0’. You are trying to install this package into a project that targets ‘.NETPortable,Version=v4.5,Profile=Profile259’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0

    1. Adam Pedley

      The Toasts package only support Profile111 or .NET Standard. Convert your project to .NET Standard, or change your PCL to support Profile111. Which normally means, remove Windows Phone Silverlight from your targets, in the Properties of your project.

  4. Motaz

    I have got the following exception when I call notify

    Binary XML file line #15: Error inflating class android.widget.Button

    I have followed all the steps explained above.

  5. Rick Morayniss

    A simple sample would be nice, since I have done what your article states, but
    The type or namespace name ‘ToastNotification’ could not be found (are you missing a using directive or an assembly reference?)

      1. Vagelis

        Hi to you,
        I tried but no success.
        I think in your example you have a small mistake. you say in the BroadcastReceiver “sWakeLock.Release();”. I think it should be “wakeLock.Release();”

        What I did:
        1) add in the android manifest ” ”

        2) Add in the mainactivity the BroadcastReceiver class and the OnNewIntent.

        The weird thing is that the notification seams not clickable!

    1. Adam Pedley

      The last version that was available was in 2.0.4. From that point, it switched to using the native toast functionality, where customization is more limited.

  6. James Albert

    Hi Adam,

    I’m confused about Snackbar vs. Notification.Builder for the different Android versions. Notification.Builder was introduced in API 11, but Snackbar was introduced in API 22 Lollipop, so I would expect Toasts.Forms.Plugin to default to Snackbar on Lollipop and higher.

    However, in both the code and your comments above, it’s the exact opposite behavior. See Notify() with NotificationStyle.Default:

    if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
    return _notificationBuilder.Notify(_activity, options);
    return _snackbarNotification.Notify(_activity, options);

    Notification.Builder “added in API level 11”

    Snackbar “added in version 22.2.0”

    1. Adam Pedley

      Yeh, I don’t know what I was thinking either. Looks like I might have accidentally switched them around.

      I should probably just default to NotificationBuilder for all versions, then have snackbar as the other option. You can set it globally to snackbar anyway, upon initialization.

      Added it to my list of things to look into, thanks for letting me know.