Skill Level: Intermediate
As of April 10, 2018, Google officially deprecated the GCM push service and APIs and announced that GCM support could disappear as early as April 11, 2019. For this reason, IBM expects most IBM Mobile App Messaging users will want to migrate to FCM.
An existing IBM Mobile App Messaging integration that uses Google Cloud Messaging (GCM) using the minimum SDK version 18.104.22.168.3.
Things to consider before migrating to Firebase Cloud Messaging (FCM)
There are some challenges when migrating from GCM to FCM. You should not create a new app key for FCM. If you create a new FCM app key, then customers with your existing GCM app will not receive messages. IBM recommends that you take the following actions to enable both GCM and FCM versions of your app to coexist and receive messages until Google turns off GCM permanently. You can use the same app key for GCM and FCM versions of your app. You do not need to create a new app key.
Import your GCM project into FCM.
Google has provided tools to import your GCM project into FCM. Use these tools to create an FCM project from your GCM project.
Change your project to use the FCM server key.
Modify the GCM app key to use the server key (not legacy server key) from your Firebase console.
Note: you do not need to create a new app key. Google has maintained compatibility between GCM and FCM, so you can continue to use the same app key for both GCM and FCM after migrating it with the Google tools. Please contact support if you are unsure about migration.
Update your AndroidManifest.xml file for FCM support:
Add the following XML to the node of your AndroidManifest.xml file for FCM support:
Remove the following GCM-only code from your AndroidManifest.xml:
Also remove all references to C2D.
NOTE: If you are starting from a version of the SDK earlier than 22.214.171.124.2, you won’t have GcmReceiver and MceGcmListenerService sections. Remove the <receiver GcmBroadcastReceiver </receiver> and the <service GcmIntentService </service> sections instead.
Build and test an FCM-enabled version of your app.
Now youâ€™re ready to build and test an FCM-enabled version of your app. Instructions for doing this can be found at Getting started with IBM Mobile App Messaging in Android (FCM).
After installing FCM over an existing GCM integration, you must update a few things. Be sure to come back here after adding Firebase support.
In your MceConfig.json:
Replace the senderId with an empty string
Change the messagingService to
(add a line that reads:
after the senderId line if it is not already there).
Next, add the Firebase code in Android Studio.
If adding the Firebase code didn’t do it automatically, remove the GCM dependency from your app’s build.gradle:
Next, add the following line right after the sdk is started:
If you are using a class that extends MceApplication, you can add it in onCreate as below. If you are using MceApplication, you will need to create a new application class that overrides MceApplication:
If you are using your own application class (not as common), call it after MceApplication.init:
This will ensure that upgraded devices know to use FCM.
Finally, delete google_app_id from your strings file (mce_sample_strings.xml in the sample app) if it exists; it is added to values/values.xml by FCM.
When testing, ensure that you test both the new install case and the migration from the GCM case. The invalidateExistingUser option in MceConfig.json might help with testing. For information about this option, see Assign new MUIDs to devices when reinstalling apps
Release an FCM-enabled version of your app.
As your users upgrade, they will migrate from using the GCM app key to the FCM app key.
If you use multiple senders, you can use the com.ibm.mce.sdk.api.fcm.FcmApi (and in particular, isFcmMessage and handleMceFcmMessage) as described in Getting started with IBM Mobile App Messaging in Android (FCM).