Jump to content
Marco Cantu

Android Firebase Push Notifications Patch Released

Recommended Posts

Is there an updated version of this good tutorial for De 10.3.2?  E.g. Firebase FMX package is no longer in the GetIt Package available and probably a lot of point works now different, but I cannot find any description or tutorial.


PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.Gcm);

When I try to execute the code built with De 10.3.2 the only what I can see is that PushService is still nil after this line. Probably something is wrong with my project settings for Android.

Edited by Christoph Schneider

Share this post

Link to post

With 10.3.2, there's just a few of the steps needed from the original tutorial:




Which are: 8 through 10, 14, one step that's actually missing from the tutorial:


In Project Options, select Application > Version Info and modify the value for "package" to match the identifier you have for the project in Firebase Console


and one additional step, which is what I expect you may be missing, namely:


In Project Options, select Application > Entitlement List, and check the Receive Push Notifications checkbox.


I think that's everything 🙂


Edited by Dave Nottage

Share this post

Link to post

Thank you Dave for this valuable information.


Unfortunately, my app is still not working. I still see that the Push-Service is nil because the app writes "Push Service failed" into the memo.

unit Unit1;


  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.StdCtrls;

  TForm1 = class(TForm)
    Memo1: TMemo;
    btnStart: TButton;
    procedure btnStartClick(Sender: TObject);
    procedure OnServiceConChange(Sender: TObject; AChange: TPushService.TChanges);
    procedure OnRecNot(Sender: TObject; const ANotification: TPushServiceNotification);

  Form1: TForm1;


{$R *.fmx}

procedure TForm1.btnStartClick(Sender: TObject);
  PushService: TPushService;
  ServiceConnection: TPushServiceConnection;
    PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.Gcm);
    if not assigned(PushService) then
      Memo1.Lines.Add('Push Service failed')
    else begin
      Memo1.Lines.Add('Push Service created');
      ServiceConnection := TPushServiceConnection.Create(PushService);
      if not assigned(ServiceConnection) then
        Memo1.Lines.Add('Service Connection failed')
      else begin
        Memo1.Lines.Add('Service Connection created');
        ServiceConnection.Active := true;
        Memo1.Lines.Add('Service Connection connected');
        ServiceConnection.OnChange := OnServiceConChange;
        ServiceConnection.OnReceiveNotification := OnRecNot;

        Memo1.Lines.Add('Service Connection query');
        Memo1.Lines.Add('DeviceID: ' + PushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceId]);
    on e: exception do
      Memo1.Lines.Add('Failure: ' + e.Message);

procedure TForm1.OnRecNot(Sender: TObject;
  const ANotification: TPushServiceNotification);
  Msg: string;
  Msg := ANotification.DataObject.ToJSON;
  Memo1.Lines.Add('Message: ' + Msg);

procedure TForm1.OnServiceConChange(Sender: TObject;
  AChange: TPushService.TChanges);
  PushService: TPushService;
  if TPushService.TChange.DeviceToken in AChange then
    PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.Gcm);
    Memo1.Lines.Add('Firebase token: ' + PushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken]);


I have enabled "Receive push notification" in the entitlement list:



I have written the package name according the FB App setting:




I imported my google-services.json in the Services section:




What I still not understand is point 14: Why I still need to build this strings.xml and attach it to the deployments? 

In the new project options under Application>Services, I entered already both values (google application ID and the default sender id). 


Of course, I tried also the described way by using strings.xml in the deployments under remote path res\values. Thanks to your ACTED tool I was able to convert my google-services.json into the following strings.xml:


<?xml version="1.0" encoding="utf-8"?>
  <string name="gcm_defaultSenderId" translatable="false">XXXXXXXXXX - MyNumber</string>
  <string name="google_app_id" translatable="false">XXXXXXXXXX - My App ID from Firebase Console</string>
  <string name="fcm_fallback_notification_channel_label" translatable="false">Notification channel for Firebase</string>

Point 15: Changing the AndroidManifest.template.xml is no longer needed, right?


Any changes in the section "Uses Permissions"?



Edited by Christoph Schneider

Share this post

Link to post



I don't know if someone still follows this post, but I want to share my experience with Delphi push notifications:


Using 10.4 to create an Android app, when running the following code :





PushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.FCM);


PushService was always nil.


I tried everything I found on the internet, but nothing worked.


The magical solution:



   FMX.PushNotification.Android, System.PushNotification;


I hope this will save some time for someone.

  • Like 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now