As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as April 11, 2019. Migrate GCM apps to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure, plus many new features. See the migration guide to learn more.

Migrate your GcmListenerService

A custom service for receiving messages (previously based on (GcmListenerService and now on FirebaseMessagingService) is now required only for the following use cases:

  • receiving messages with notification payload while the application is in foreground

  • receiving messages with data payload only

  • receiving errors in case of upstream message failures.

If you don't use these features, and you only care about displaying notifications messages when the app is not in the foreground, you can completely remove this service.

Update the Android Manifest

Before

<service
    android:name=".MyGcmListenerService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
</service>

After

<service
    android:name=".MyFcmListenerService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Update your GcmListenerService

Change MyGcmListenerService.java to extend FirebaseMessagingService and update the signature of the method onMessageReceived(). This example updates the service name to MyFcmListenerService.

MyGcmListenerService.java Before

public class MyGcmListenerService extends GcmListenerService {
  @Override
  public void onMessageReceived(String from, Bundle data){
    ...
  }

  ...
}

MyFcmListenerService.java After

public class MyFcmListenerService extends FirebaseMessagingService {
  @Override
  public void onMessageReceived(RemoteMessage message){
    String from = message.getFrom();
    Map data = message.getData();
  }
  ...
}

Send feedback about...

Cloud Messaging
Cloud Messaging