[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

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