Migrating to FCM from GCM

Save

As you know Google introduced the new FCM (Firebase Cloud Messaging) as an upgrade to GCM, Its not mandatory to update your app to FCM as the GCM is still functional and the update is not affecting it. But

its recommended to upgrade so that you can get the new features. And for the new apps I’ll recommend  to use FCM. So lets start migration our existing android app to FCM.

Firstly import your project to Firebase console and provide the package name and SHA-1. Then download the new google-services.json file and replace it with your existing file in your project.

Please note that now you don’t need any kind of permission in your manifest like in GCM so remove all the GCM related permissions from manifest file. In the app level gradle file change the dependency from

to

And now all the major changes just replace the code in manifest from

to the new code

The new MyInstanceIDListenerService.java

The FCMListenerService.java

An you are ready to go. All the setup is ready just a little bit change, on the Activity in which you want to create the FCM token in your application just add the code

and the function sendTokenToServer(). And FCM is implemented but don’t forgot that now the API-Key and Sender Key is changed so update them on the server side.

You can also test the application notification from Firebase console as you can directly send message from there. For any assistance you can visit the link.

. . .
Discuss on Helpdesk

Leave a Comment

Your email address will not be published. Required fields are marked*


8 comments

  • Anmol Arora
    I’ve already migrated and the new fcm configuration is working fine. But my concern is that I’m not able to send push notification to the GCM registration tokens. When I try sending the push to old gcm registration token through Firebase Console it fails. Can you give any input on that?
    • aastha gupta
      Hi Anmol, please check your Server API key, I guess it must have changed while migrating to FCM. If its changed then you can’t send messages to those GCM tokens from FCM console.
  • aastha gupta
    Hi Anmol, you can’t send messages to earlier GCM registered devices through FCM console as the Server_API_key is changed during migration to FCM. And older GCM tokens or topics (in case of topic messaging) are connected to older API_key only.
    You can use your former method of sending messages for contacting GCM users and FCM for new ones (but be sure of the API_key you are using) for 2- 3 updates after that most of your users must have been updated the app. Then you can completely move on to FCM console.
  • diti
    it has another method for sendin api requests, dont use the old url and request data, see the documentation for server request for Firebase, here is an example on server of FCM-server request with PHP:
    https://uploads.disquscdn.com/images/b5115819254f5a3c143b407854a3704f8301919076a55595ed59c1339e5bf560.png
    • Aastha (Moderator)
      Yes FCM do have another method but its not strictly required to change the api. You can check it here
      Please check the last line.
  • Alexander Ustinov
    It’s cool, but what will be with old apps on GCM?

    Will It work correctly?

    • Aastha (Moderator)
      They will be fine as mostly the Server key (API key) remains same. So you can send notifications to them as well but not from Firebase console.
    • aastha gupta
      They will be fine as mostly the Server key (API key) remains same. So you can send notifications to them as well but not from Firebase console.
  • css.php
    Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home