The local notification plugin provides a way to show local notifications from Xamarin.Forms apps.
Plugin.LocalNotificationAvailable on NuGet: https://www.nuget.org/packages/Plugin.LocalNotification- Install into your platform-specific projects (iOS/Android), and any .NET Standard 2.1 projects required for your app.
| Platform | Supported | Version | Notes |
|---|---|---|---|
| Xamarin.iOS | Yes | iOS 10+ | |
| Xamarin.Android | Yes | API 19+ | Project should target Android framework 10.0+ |
var notification = new NotificationRequest
{
NotificationId = 100,
Title = "Test",
Description = "Test Description",
ReturningData = "Dummy data", // Returning data when tapped on notification.
NotifyTime = DateTime.Now.AddSeconds(30) // Used for Scheduling local notification, if not specified notification will show immediately.
};
NotificationCenter.Current.Show(notification);public partial class App : Application
{
public App()
{
InitializeComponent();
// Local Notification tap event listener
NotificationCenter.Current.NotificationTapped += OnLocalNotificationTapped;
MainPage = new MainPage();
}
private void OnLocalNotificationTapped(LocalNotificationTappedEvent e)
{
// your code goes here
}
}Project should target Android framework 10.0+
To receive Local Notification tap event. Include the following code in the OnNewIntent() method of MainActivity:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
.....
// Must create a Notification Channel when API >= 26
// you can created multiple Notification Channels with different names.
NotificationCenter.CreateNotificationChannel();
.....
LoadApplication(new App());
.....
NotificationCenter.NotifyNotificationTapped(Intent);
}
protected override void OnNewIntent(Intent intent)
{
NotificationCenter.NotifyNotificationTapped(intent);
base.OnNewIntent(intent);
}
}You must get permission from the user to allow the app to show local notifications. Also, To receive Local Notification tap event. Include the following code in the FinishedLaunching() method of AppDelegate:
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override void WillEnterForeground(UIApplication uiApplication)
{
Plugin.LocalNotification.NotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
}
}Setting up Notification Channels
Notification with a Sound-File
In Visual Studio, confirm that SourceLink is enabled. Also, Turn off "Just My Code" since, well, this isn't your code.
https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink
Only support iOS and Android for the moment.
- Please go to 4.1.4 Documentation, if you are referencing a version below 5.0.0.
- Version 5.* has setup differences in Android if upgrading from version 3.*
- Please go to 3.0.2 Documentation, if you are referencing a version below 4.0.0.
- Version 4.* has setup differences in Android if upgrading from version 3.*
- Please go to 2.0.7 Documentation, if you are referencing a version below 3.0.0.
- Version 3.* has breaking changes if upgrading from version 2.*
Contributions are welcome. Feel free to file issues and pull requests on the repo and they'll be reviewed as time permits.
- Thank you for the Icons by DinosoftLabs and Iconic Hub
- Thank you for the sound file by Notification sounds

