[F/OS] FCM - Firebase Cloud Messaging [v2.0.0]

Firebase-Cloud-Messaging

An extension for MIT App Inventor 2.
Firebase Cloud Messaging receiver extension. Developed by Hridoy.

:memo: Specifications


:package: Package: com.hridoy.fcm
:floppy_disk: Size: 1 MB
:gear: Version: 2.0.0
:mobile_phone: Minimum API Level: 14
:date: Updated On: 26-05-2026 SAST
:laptop: Built using: FAST v6.1.0


All Blocks


Events

Events (5)

1. TokenReceived

TokenReceived

Fired when the FCM token is automatically refreshed by Firebase.
Send the new token to your server immediately.

Parameter Type Desciption
token text new FCM registration token

2. NotificationReceived

NotificationReceived

Fired when a notification-type FCM message arrives.
Always fires in foreground.

Parameter Type Description
from text sender ID
messageId text unique message identifier
style dictonary notification style data in dictonary
data dictonary extra data payload in dictonary

3. MessageReceived

MessageReceived

Fired when a data-only FCM message arrives.
Delivered regardless of app state. No notification is shown.

Parameter Type Description
from text sender ID
messageId text unique message identifier
data dictonary extra data payload in dictonary

4. AppOpenedFromNotification

AppOpenedFromNotification

Fired when the user taps a notification and the app opens.

Two scenarios:
β€’ App killed β€” call GetLaunchNotification() in Screen.Initialize
β€’ App in background β€” fires automatically via onResume

Parameter Type Description
messageId text ID of the tapped notification
data dictonary extra data payload in dictonary

5. ErrorOccurred

ErrorOccurred

Fired when any FCM operation fails outside of a callback context.

Parameter Type Description
operation text name of the method that failed
message text error description

Methods

Methods (11)

1. Initialize

Initializes Firebase with your project credentials.
Call this once at app startup before any other FCM method.

Parameter Type Description
apiKey text Web API key
applicationId text App ID (e.g. 1:123:android:abc)
projectId text Project ID (e.g. my-app-123)
senderId text Sender ID / Cloud Messaging number
callback procedure Need 2 param:
β€’ status (boolean: true = success, false = failure)
β€’ errorMessage (text: empty if success)

2. GetLaunchNotification

GetLaunchNotification

Call this in Screen.Initialize to check if the app was opened
by tapping a notification while the app was killed or in background.

If the app was opened from a notification tap, fires
AppOpenedFromNotification immediately.
If the app was opened normally, does nothing.

Recommended call order in Screen.Initialize:

  1. call FCM.Initialize(...)

  2. In Initialize callback (status = true):
    β†’ call FCM.GetLaunchNotification()
    β†’ call FCM.GetToken(...)


3. SetNotificationChannel

Configures the Android notification channel for all FCM notifications.
Call before the first notification is displayed.
No-op on Android 7 and below.

Parameter Type Description
channelId text unique ID (e.g. 'my_channel')
channelName text name shown in system settings
channelDescription text description shown in system settings

4. GetToken

GetToken

Retrieves the current FCM registration token from Firebase.
Always fetch fresh before sending to your server.

Parameter Type Description
callback procedure Need 2 parameters:
1) token (text: FCM token, empty if failed)
2) errorMessage (text: empty if success)

5. GetCachedToken

GetCachedToken

Returns the last known FCM token from local cache.
Returns empty string if no token has been fetched yet.
Use GetToken() to retrieve a fresh token from Firebase.

  • Return type: text

6. SubscribeToTopic

SubscribeToTopic

Subscribes this device to an FCM topic.
Checks local cache first β€” skips Firebase call if already subscribed.
Topic names must match [a-zA-Z0-9-_.~%] and be under 900 chars.

Parameter Type Description
topic text the topic name
callback procedure Need 3 parameters:
1) status (boolean: true = success, false = failure)
2) topic (text: the topic name)
3) errorMessage (text: empty if success)

7. UnsubscribeFromTopic

UnsubscribeFromTopic

Unsubscribes this device from an FCM topic.

Parameter Type Description
topic text the topic name
callback procedure Need 3 parameters:
1) status (boolean: true = success, false = failure)
2) topic (text: the topic name)
3) errorMessage (text: empty if success)

8. SubscribedTopics

SubscribedTopics

Returns the list of topics this device is currently subscribed to.
Reads from local cache. No network request.
Returns empty list if not subscribed to any topics.

  • Return type: list

9. DeleteToken

DeleteToken

Deletes the current FCM registration token.
Use on user logout to stop receiving targeted notifications.
A new token is generated on the next GetToken() call.

Parameter Type Description
callback procedure Need 2 parameters:
1) status (boolean: true = success, false = failure)
2) errorMessage (text: empty if success)

10. RequestNotificationPermission

RequestNotificationPermission

Requests POST_NOTIFICATIONS runtime permission on Android 13+.
No-op on Android 12 and below.

11. IsNotificationPermissionGranted

IsNotificationPermissionGranted

Returns true if POST_NOTIFICATIONS permission is granted.
Always returns true on Android 12 and below.

  • Return type: boolean

Properties

Properties (1)

1. ShowForegroundNotifications

ShowForegroundNotifications


ShowForegroundNotifications

Controls whether notifications are shown when the app is in foreground.
Resets to true each session β€” call in Screen.Initialize to change.

β€’ true = show notification (default)
β€’ false = suppress, only fire NotificationReceived event

  • Input type: boolean

Usage

:warning: You have to upload google-services.json to assets

Demo

Download Latest v2.0.0

Event based methods v2.0.0

ChangeLog

v1.0.0

aix : com.hridoy.fcm.aix (6.3 MB)

aia : FCM_v1_0_0.aia (6.3 MB)


v1.0.1
  • Uses updated proguard rules for R8 shrinker
  • AIX size reduced to 974 KB

aix : com.hridoy.fcm.aix (974.0 KB)

aia : FCM_v1_0_1.aia (729.9 KB)


v1.0.2
  • Replaced R8 with ProGuard
  • App freeze at OnMessageRecieved() bug fixed

aix :com.hridoy.fcm.aix (972.7 KB)

aia : FCM_v1_0_2.aia (979.4 KB)


v2.0.0 (Latest)

:police_car_light: Breaking Changes

NotificationReceived

  • NotificationRecived() event now sends styles insted of title,body

:new_button: New Features

  • Small Icon Support (Full image URL or Asset image)
  • Different Notification Types Added (5)
    • Basic
    • Big Text
    • Big Picture
    • Individual Messages
    • Group Messages

Open Source

3 Likes

Thanks for your contribution :+1:
Have you tried optimizing the extension size using ProGuard or R8?

I haven't optimized it yet. I'll most likely use R8, but first I need to collect the required ProGuard/R8 keep rules for all the Firebase and App Inventor runtime classes.

I tried ProGuard once before, but it caused 'NoClassDefFoundError' issues at runtime, probably because some required classes were obfuscated or removed incorrectly.

:fire: Update - v1.0.1

  • AIX size reduced to 974 kb

:fire: Update - v1.0.2

  • Replace R8 with ProGuard
  • App freeze at OnMessageRecieved() bug fixed

Download files from first post

1 Like

:fire: Update V2.0.0

:police_car_light: Breaking Changes

NotificationReceived

  • NotificationRecived() event now sends styles insted of title,body

:new_button: New Features

  • Small Icon Support (Full image URL or Asset image)
  • Different Notification Types Added (5)
    • Basic
    • Big Text
    • Big Picture
    • Individual Messages
    • Group Messages

Demo

Use FCM Sender for this

1 Like

Great project. thanks for your contribution. Can you tell me how you compile it to get such a small size? when I compile it from source code it’s over 6mb

I used ProGuard
You can see my ProGuard config for this project

2 Likes

I got it. Thanks a lot

Hi! I just updated to FCM v2.0.0 and I'm having trouble with the "callback" socket in both Initialize() and GetToken(). It's a value-shaped socket (not a statement input), but I can't find what type of block is supposed to plug into it. Could someone share a screenshot of the actual blocks used for Initialize + GetToken with the callback connected? Thanks in advance!

You have to use anonymous procedure.
Blocks > Procedure > More > createProcedure

1 Like

Thanks for the quick reply! I tried to find that path but I'm stuck β€” in my Procedures drawer I only see 4 blocks: "to procedure do", "to procedure result", "call InitCallback", and "call procedure" (with a dropdown). I don't see any "More" option or link, even after scrolling and zooming out. Could you clarify exactly where "More" is? Is it a small link/button inside the Procedures drawer flyout, a right-click option, or something else? A quick screenshot or screen recording of just that step would help a lot. Thanks for your patience!

click the β€˜+’ on the left of procedures:

FCM Extension β€” Update v2.1 (Event-Based)
no functional change.

All callback-based functions converted to pure event-based blocks β€” no more callback parameter to wire up, just plug a when block directly.

Changed:

  • Initialize β†’ fires InitializeCompleted

  • GetToken β†’ fires TokenReceived

  • SubscribeToTopic β†’ fires TopicSubscribed

  • UnsubscribeFromTopic β†’ fires TopicUnsubscribed

  • DeleteToken β†’ fires TokenDeleted

  • All failures now go through the existing ErrorOccurred event

    Original extension by Hridoy β€” this is a workflow/usability update on top of it.
    SimpleFCM.aix (1011.6 KB)

1 Like

Hi!

I want to use this extension FCM with extension itoo. But they don't work together. When the app is minimized to the notification shade, the FCM extension doesn't receive messages. How can this problem be solved?

Set ShowForegroundNotifications to True

Thanks. I did that right away, though. I specifically want to use the MessageReceived block.
If I don't use itoo and rely on the MessageReceived block instead, everything works only while the app is active; if the app is closed, nothing happens. I’ve tried various approaches, message types, and settings, but the result is always the same.

When I use itoo, I create a background process that generates a notification shade for the app, making it accessible even when the app is closed. In this scenario, I need to create the appropriate function and register an event handler for FCM. I’ve tried different methods, but it simply won't work at all. Here is a snippet of my code.

An event can't be triggered in the background!

What about showing your relevant blocks?
Also see again the usage example

You should get a notification also if the app is in the background

Anf if you want to use itoo to do more than just displaying a notification, then use the latest itoo version

Taifun

in my application I use the latest version of itoo. And it works well with events in background. Everything works well for me with Timer events for Clock component and GotText for Web component.

But when I want to bind itoo to MessageReceived event for FCM it doesn't work.

P.S. In my project I use FCM version without callback, only with Event (simpleFCM.aix). Maybe there is some conflict at the Android level, but in the OnError event for FCM it is not shown, although I track all errors. I don't know it.

"MessageReceived" works when the app is paused.

Please try implementing it without "itoo" and store the data in TinyDB instead. Once implemented, verify the stored data in TinyDB to confirm that everything is working as expected.

1 Like

The last version of itoo ( 4.5.0 ) does not have the RegisterEvent ( shown in your post ).

You could consider switching to last version