Introduction

Push notifications are essential for modern mobile applications, enabling real-time
updates, alerts, and user engagement.
In .NET MAUI, integrating push notifications on Android requires configuration in
Firebase, Android Manifest, and your MAUI project.
This article provides a step-by-step guide to implementing Firebase Cloud Messaging
(FCM) push notifications for .NET MAUI Android apps.

Overview of .NET MAUI

.NET MAUI (Multi-platform App UI) is a cross-platform framework for building native
mobile and desktop applications using C#.
Key advantages:
• Single project structure
• Native performance
• Unified APIs
• Supports Android, iOS, macOS, Windows
Push notification implementation in MAUI uses platform-specific features—this guide
focuses on Android.

Prerequisites

Before getting started, ensure you have:

Firebase Setup (FCM Configuration)

Step 1: Create Firebase Project

  1. Go to Firebase Console
  2. Click Add Project
  3. Enter Project Name → Continue
  4. Disable/Enable Google Analytics as required
  5. Create Project

Step 2: Add Android App to Firebase

  1. Inside project → Add App → Android
  2. Enter your Package Name

Example: com.companyname.myapp

  1. Register App
  2. Download the file google-services.json
  3. Place it in your MAUI project: Platforms/Android/google-services.json

Add Required NuGet Package

Install: Plugin.Firebase.CloudMessagingConfigure Android Manifest
In Platforms/Android/AndroidManifest.xml add:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Initialize Firebase in MAUI Application

In MauiProgram.cs:

builder.Services.AddFirebaseMessaging();

In MainApplication.cs:

public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership tran) : base(handle, tran)
{ }
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
public override void OnCreate()
{
base.OnCreate();
Firebase.FirebaseApp.InitializeApp(this);
}
}

Implement Push Notification Handler

Create class:
MyFirebaseMessagingService.cs

using Firebase.Messaging;
[Service(Exported = true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
public override void OnMessageReceived(RemoteMessage message)
{
var body = message.GetNotification()?.Body;
var title = message.GetNotification()?.Title;
ShowNotification(title, body);
}
private void ShowNotification(string title, string message)
{
var builder = new NotificationCompat.Builder(this, "default")
.SetContentTitle(title)
.SetContentText(message)
.SetSmallIcon(Resource.Drawable.notification_icon);var manager = NotificationManagerCompat.From(this);
manager.Notify(1, builder.Build());
}
}

Retrieve FCM Token

var token = await FirebaseMessaging.Instance.GetToken();
Console.WriteLine("FCM Token: " + token);

Use this token to send notifications using:
• Firebase Console
• Azure Notification Hub
• Custom backend API

Sending a Test Notification

Option 1: Firebase Console

Go to Cloud Messaging → Send Notification, enter title & message and click Send.

Option 2: Postman

Call FCM API:

POST https://fcm.googleapis.com/fcm/send

Body

{
"to": "your_device_token",
"notification": {"title": "Hello",
"body": "Test message"
}
}

Best Practices

• Store tokens securely in backend
• Handle token refresh
• Group notifications
• Support silent data messages
• Follow Android 14 notification guidelines

Conclusion

Implementing push notifications in .NET MAUI for Android is straightforward once
Firebase is configured correctly. This guide covered the full setup—from Firebase
settings to MAUI configuration, token retrieval, and testing notifications.
With this, you can integrate real-time updates into your MAUI application.

Resource

https://learn.microsoft.com/dotnet/maui/android/platform-integration/notifications/push