Enabling Firebase Push Notifications in a Titanium SDK Android App
Learn how to register and receive FCM push messages in a Titanium Android app, from adding the ti.fcm module to handling token retrieval and troubleshooting common pitfalls.
30 Jul 2026, 05:51 UTC

Desired Outcome
Make a Titanium Android application that can register with Firebase Cloud Messaging (FCM) and display a local alert whenever a remote push message arrives.
Prerequisites
- Titanium SDK 7.5 or newer (the
ti.fcmmodule is still bundled but marked deprecated; use it only if you cannot upgrade to a newer push‑notification approach). - Android API level 21 or higher.
- Firebase project with a valid
google-services.jsonfile. - Physical Android device (emulators can work but may block FCM traffic).
- Internet connectivity on the device.
- In
tiapp.xml, enable theti.fcmmodule and add required permissions.
Procedure
- Add the module to
tiapp.xml```xml ti.fcm ```
Also ensure the
ti.fcmmodule is listed undermodulesfor the Android platform. No additionalti.fcmSDK download is needed because it ships with Titanium. - Place
google‑services.jsonin the project rootCopy the file you downloaded from the Firebase console into the same directory that contains
tiapp.xml. Titanium will automatically bundle it into the APK. - Request notification permission at runtime
FCM requires the
RECEIVEpermission. Titanium automatically addsandroid.permission.INTERNETandandroid.permission.WAKE_LOCKwhen the module is present, but you must request the notification permission explicitly for Android 13+.```javascript // main.js Ti.FCM.requestPermission({ alert: true, badge: true, sound: true }, function(e) { if (e.success) { console.log('FCM permission granted'); } else { console.error('FCM permission denied', e.error); } }); ```
- Implement a push‑event listener
```javascript Ti.FCM.addEventListener('push', function(e) { // e.message contains the notification body Ti.UI.createAlertDialog({ title: 'Push Received', message: e.message || 'No message body' }).show(); }); ```
When a remote message arrives, the listener will trigger and display an alert.
- Retrieve and log the FCM token
```javascript var token = Ti.FCM.getToken(); console.log('FCM token:', token); if (!token) { console.warn('Token is empty – registration may have failed'); } ```
Keep this token handy; you’ll need it to send a test message from the Firebase console.
- Build and deploy
Run the standard Titanium build command targeting a physical device:
ti build -p android -T device -BMake sure the device is connected via USB and has USB debugging enabled.
Expected Checks
- Token Verification
Open the app’s console (logcat) and confirm a non‑empty string is printed for
FCM token. If the token is missing, the app likely failed to register. - Test Message Delivery
In the Firebase console, navigate to Cloud Messaging → Send your first message. Use the token printed earlier as the target. Send a notification with a short title and body.
On the device, the alert dialog defined in the listener should appear almost instantly.
- Logcat Inspection
Search for
ti.fcmorFirebaseMessagingServicelogs. Typical messages include "FCM registration succeeded" or error codes such ascom.google.android.gms.common.api.ApiException. Any exception indicates a configuration issue.
Troubleshooting & Recovery
- Token is empty or missing
- Verify
google-services.jsonis in the project root and not corrupted. - Check that the file contains the correct
client>project_numberandclient>client_identries. - Ensure the device has internet access and no VPN or firewall blocks
fcm.googleapis.com. - Re‑install the app: uninstall from the device, clean the build folder (
ti clean), and rebuild.
- Verify
- No alert appears on message receipt
- Confirm the listener was added before any push messages could arrive. Place the listener code at the top of
main.js. - For Android 13+, create a notification channel. Titanium’s
ti.fcmmodule automatically creates a default channel nameddefault, but you can override it:Ti.FCM.setChannel({id: 'default', name: 'General', importance: Ti.FCM.IMPORTANCE_HIGH}); - Check that the device is not in Do Not Disturb mode or that the app is not force‑stopped.
- Look for
android.app.RemoteInputerrors in logcat indicating the notification payload is malformed.
- Confirm the listener was added before any push messages could arrive. Place the listener code at the top of
- FCM service disabled in Firebase
- In the Firebase console, go to Project Settings → Cloud Messaging and confirm that the “Firebase Cloud Messaging” service is enabled.
- Ensure the API key in
google-services.jsonmatches the one on the console.
Summary
By adding the ti.fcm module, supplying a valid google-services.json, requesting runtime permission, and listening for the push event, a Titanium Android app can receive Firebase push notifications. Verify the token, send a test message, and inspect logcat for any registration or delivery errors. If the token is missing or notifications fail, check the JSON placement, internet connectivity, and Android 13 notification channel requirements.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.