1. Create your Firebase project

2 Request your FCM Token

Sender Id

AndroidManifest.template.xml

EJNIException with message 'java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) } without permission com.google.android.c2dm.permission.RECEIVE'

3 Receive your first FCM Push notification

Jordi

Embarcadero MVP.

A comprehensive step by step guide, covering everything you need to know to receive push notifications to yourdevice using Firebase Cloud Messaging and the latest Delphi 10.1 Berlin update 2.Push notifications let your application notify a user of new messages or events even when the user is not actively using the application(downstream messaging) ( Parse.com ). On Android devices, when a device receives a push notification, the application's icon and a message appear in the status bar. When the user taps the notification, they are sent to the application. Notifications can be broadcast to all users, such as for a marketing campaign, or sent to just a subset of users, to give personalised information. To provide this functionality I will rely onwhich is the new version of Google cloud messaging ) and Delphi to develop the Android application.Create your Firebase project by visiting the console if you still don't have one and in this project create an Android App.I already have one project so I will use this one for my demo. Once in the project, go toAnd give it a sensible name. In my case I called the package. This package name is important as it will be referenced later on. Once you click Add App, you will receive afile which contain information that we will use later.The package name is defined in your Delphi project:So make sure that everything matches with the name you give to your Firebase application as the manifest file will contain this information.Now that we have our project configured, we need to requesta uniquefor our Android device. You can see the description here as to how to get the FCM token via Android Studio, but I will show the necessary steps to get the same value from our Delphi application.Basically we are trying to get the same value from. We will achieve the same behaviour by using TPushServiceManager which is the unit responsible for handling push notifications.The following code snippet tries to request the FCM token viaNow, to allow this code to work correctly, we will have to configure few things.In the source code snippet above, I'm mentioning the SENDER ID. This sender id, can be found underThis is the value you have to put here:PushService.AppProps[TPushService.TAppPropNames.GCMAppID] := '';Knowing that theis actually thehas been a quite a struggle for some users and you can see my answer on Stack overflow In the Delphi IDE, go to your->and set the propertytoBefore we try to run the code above, we'll have to configure thefile to grant our device permissions to connect to. If you don't configure the permissions, you might run into an exception like the one below:See the code snipped below for reference:The full source code of the solution can be found here for reference where you can find the manifest files.Once everything is configured, we can now test if we can receive the. Here is a screenshot of my project so you can see that there are two buttons, one to receive the token and the other one to store this token somewhere so the system that sends the notification knows the receiver.Let's see the project in action here:As you can see in the image above, I get theand the. The one we are interested in is the. This token is quite large so it does not appear completely on the screen.Now we need to configure what to do when we receive a notification and how this notification is built.The following code snipped will configure theevent and will display a notification using the TNotificationCenter class.Notice that the ServiceNotification variable contains a DataKey member which contains a JSON envelope. This object will contain all the information of our push notification. Here you can see how this notification looks like:Notice that the message is part of theproperty and this one is the one that we will use for ourmethod.Let's see the application in action:Here you can see side by side my Android device andsystem. Once the application is ready to receive notifications, you just need to send the notification using the configured app or the token if you want to target a single device.Next step is to store these tokens on the cloud and use your own system to deliver those messages.Please, do not hesitate to contact me if you have any further questions.