This section describes simple steps required to create an application to support Google Cloud Messaging in Android device. For more information on creating app to support GCM, refer to Set up a GCM Client App on Android.
- Register the client application.
- Get a configuration file from Google Developer console to add to your project. For more information, refer to Get a configuration file.
- Add the configuration file to your project. For more information, refer to Add the configuration file to your project.
- Setup Google play services.
- Edit your application's Manifest.
- Check for Google Play Services APK.
- Obtain a registration token.
For GCM to work the following classes are added in the Manifest.xml file as service. The Manifest.xml file calls the methods included in their respective classes when GCM functionality is invoked.
RegistrationIntentService- This class handles the registration of the client application with the GCM connection server. When an app registers, it receives a registration token and sends it to the app server (the WRTC gateway) using the method
sendRegistrationToServer(). The client app stores a Boolean value indicating whether the registration token has been sent to the server.
MyGCMListenerService- This class extends the
GCMListenerServiceand implements the
onMessageReceived()callback when a GCM message is received. When this callback is invoked, the application calls
sendNotification()to create and show a notification on the device.
MyInstanceIdListenerService- This class extends the
InstanceIDListenerServiceand implements the
onTokenRefresh()callback which is invoked when the registration token gets refreshed.
For more information on Google Cloud Messaging feature, refer to Google Cloud Messaging Support in WRTC.