Documentation

Migrating from FCM (Android)


Migrating to Pushy from Firebase Cloud Messaging is extremely simple.

There are only a few trivial changes to perform. The rest of your implementation stays the same, including token persistence, push notification logic, and even push payload.

Remove FCM Dependency

Open your app-specific build.gradle file.

Find:
compile 'com.google.firebase:firebase-messaging:9.6.1'

Delete the line entirely.

Note: Your referenced firebase-messaging version may differ slightly.

Remove Firebase Dependency

If you wish to completely remove Firebase from your app, reopen your app-specific build.gradle file.

Find:
apply plugin: 'com.google.gms.google-services'

Delete the line entirely.


Open your project-wide build.gradle file.

Find:
classpath 'com.google.gms:google-services:3.0.0'

Delete the line entirely.

Note: Your referenced google-services version may differ slightly.


Finally, delete the google-services.json file within your app's folder.

Remove Manifest Declarations

Delete the following declarations in your AndroidManifest.xml:

  • The <service> containing the com.google.firebase.MESSAGING_EVENT action.
  • The <service> containing the com.google.firebase.INSTANCE_ID_EVENT action.

Note: You may delete the class file linked to the INSTANCE_ID_EVENT action as we will not be needing it anymore. However, do not delete the MESSAGING_EVENT class file just yet, we'll need it for later.

Get the SDK


Visit Get the SDK and follow along. Return to this guide when you're done.

Update Registration Call


You must replace FCM's device registration call with Pushy.register(Context).

Find:
FirebaseInstanceId.getInstance().getToken()
Replace with:
Pushy.register(this)

Your code may slightly differ.

Note: Pushy.register(Context) is a synchronous, blocking call, so make sure to only execute it from within a background thread. We provide a sample asynchronous implementation if you'd like.

Additional Note: Pushy device tokens are static, there is no need to monitor for changes like with FCM.

Modify Launcher Activity


Visit Modify Launcher Activity and follow along. Return to this guide when you're done.

Modify AndroidManifest


Visit Modify AndroidManifest and follow along. Return to this guide when you're done.

Setup BroadcastReceiver


Visit Setup BroadcastReceiver and follow along. Return to this guide when you're done.

Migrate Notification Logic


Copy the notification handling logic from your old FirebaseMessagingService into the new PushReceiver class you just created. You will need to modify your code to parse the notification payload from the BroadcastReceiver intent extras instead of FCM's RemoteMessage.

Unlike Firebase Cloud Messaging, we do not stringify your payload data, except if you supply JSON objects or arrays. This means that if you send {"id": 3}, you'd retrieve that value in your BroadcastReceiver using intent.getIntExtra("id");


Also, unlike Firebase Cloud Messaging, we will always invoke your PushReceiver when notifications are received, even when your app is in the foreground.

Furthermore, on Android, we currently do not support the notification parameter which builds and displays a notification if your app is in the background. Instead, you can send the relevant parameters within the data payload of push notifications and then implement logic to build and display a system notification.

You may delete the FirebaseMessagingService class file now.

Modify Backend Logic


All that's left to do is modify the URL of the HTTP request used to send push notifications to devices in your backend code.

Find the part of your backend code that connects to FCM to send push notifications. All you need to do is replace the URL to the FCM endpoint with the URL to our Send Notifications API. The FCM parameters data and registration_ids are supported in our API to make migration easy.

Find:
https://fcm.googleapis.com/fcm/send
Replace with:
https://api.pushy.me/push?api_key=SECRET_API_KEY

Make sure to replace SECRET_API_KEY with your app's Secret API Key listed in the Dashboard.

Note: Check out our Send Notifications API Reference for more information about this API.

All done!


Now that you've migrated both the Android code and backend logic, try to send a push notification from your backend to verify that everything works.

You may use this page to send a test notification containing {message: "Hello World!"} to your device.

We thank you for choosing Pushy. Let us know if you have any ideas on how to improve our service.