I have decided to build a cross-platform Notifications Client used to receive push notifications when a long-running system needs it. This Notifications Client is generic, and not tied to a specific system or application, but serves as a receiver and repository for all kinds of notifications.
This article is part of a series. In here, we will set the Firebase Cloud Messaging (FCM) service and prepare it to be an intermediate between Azure Notification Hub and our mobile app on Android.
Android notifications are sent through a service called Firebase Cloud Messaging (this is a Google service). When you use an "aggregation service" like Azure Notification Hub, this service will communicate with FCM to send the notification to all the Android devices who registered for it. Similarly, Notification Hub will also communicate with corresponding services for Windows (we will set this later) and for iOS.
Note: For this to work, the Android device needs to support Google Play Services. The Azure Notification Hub also supports Baidu as a target, but this won't be treated in this article.
To start, we need to navigate to the Firebase console. Then follow the steps:
- Click on Create a project.
- In the first step, enter a name for your new project. You can choose any name, this is just for management purposes.
- You can choose to enable analytics or not. In my case, I decided to turn this off, because I will be using Application Insights on Azure to monitor the system, and I don't really need a separate analytics solution just for the Android devices. But your mileage may vary...
- The new project will be provisioned, so just wait for a moment until it is ready.
Firebase can be used for quite a lot of things next to push notifications, but we are not going to use these features here. The main point of this project is to be a gateway between Azure Notification Hub and the Android devices.
- Now we will configure the Android application. This is quite easy. First, in the "Get started by adding Firebase to your app" section, click on the Android icon.
- Next, we will link the Firebase project to the Android application that we will create later. You need to enter an Android package name. You can also enter a nickname for this app, this is just for management purpose.
The Android package name is of the form
com.[yourcompanyname].[yourapplicationname]. Make sure to write it down for later.
- On the next step, download the
google-service.jsonfile and save it in a safe location. This file contains all the information needed by the Android devices to register with the Firebase system to get the notifications.
- On the next screen, you can just press
Continue to console.
Now we will write down the secret keys that we'll need to use in the Android application. Later we'll use these keys in the Xamarin code, and even later we'll save these keys to Azure Key Vault for safe keeping.
In the Firebase Console, select your application.
In the application dashboard, click on the button with the small Android icon, and the name of your app.
- Click on the Settings icon
- Click on
- Copy the Server Key and save it somewhere for later.
That's it, you have created and configured a new Google Firebase Cloud Messaging project, and downloaded the file you need.
If you lose the
google-services.jsonfile, you can always retrieve it from the Firebase console.
You have also retrieved the Server key which we will use to configure the Azure Notification Hub. Make sure to save it!
In the next article (coming soon), we will see how to build an "empty" Xamarin Forms application and configure it to receive the notification from FCM.