Home > Blockchain >  Topic subscription of Firebase Cloud Messaging in Android app using Delphi 11
Topic subscription of Firebase Cloud Messaging in Android app using Delphi 11

Time:02-28

I'm writing an Android app that needs to receive push notifications using Delphi 11. After following the article at https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Firebase_Android_Support, I can now register my phone with the FCM service and receive push notifications sent with the specific device token (received from FCM after successful registration). But the article doesn't mention how to make an app subscribe to a topic such that my phone can receive push notifications sent with a topic. Can anyone please share me with a suggestion or pointer for that? Thanks a lot.

CodePudding user response:

If it's just for Android, you could use these:

uses
  Androidapi.JNI.Firebase, Androidapi.Helpers;

procedure SubscribeToTopic(const ATopicName: string);
begin
  TJFirebaseMessaging.JavaClass.getInstance.subscribeToTopic(StringToJString(ATopicName));
end;

procedure UnsubscribeFromTopic(const ATopicName: string);
begin
  TJFirebaseMessaging.JavaClass.getInstance.unsubscribeFromTopic(StringToJString(ATopicName));
end;

You should probably make sure that the push service has been created before calling these

  • Related