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:

 

  https://community.idera.com/developer-tools/b/blog/posts/firebase-android-push-notification-support-with-rad-studio-10-3-1

 

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;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btnStartClick(Sender: TObject);
var
  PushService: TPushService;
  ServiceConnection: TPushServiceConnection;
begin
  try
    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]);
      end;
    end;
  except
    on e: exception do
      Memo1.Lines.Add('Failure: ' + e.Message);
  end;
end;

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

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

end.

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

image.thumb.png.414f575f1b80d866978ca0b1f9bc11a9.png

 

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

 

image.thumb.png.87b730001a25dbe66e7afcda32503ba2.png

 

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

 

image.thumb.png.b63b8dd265f7713ff000cb0ba15eaa54.png

 

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"?>
<resources>
  <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>
</resources>

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

Hello,

 

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 :

 

uses 

   System.PushNotification;

 

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:

 

use 

   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

×