Push Notifications Using GCM
Before you can send push notifications to Android devices you need to set up Google Cloud Messaging and obtain two things:
- A google-services.json configuration file that will be embedded in your app and contains things like the sender ID which is needed to link your actual app to the Google services app in your account and is used to retrieve the registration ID that will be sent to deltaDNA and is used to send GCM messages (push notifications) to the device.
- The Server API Key that will be entered in to the deltaDNA website to enable the deltaDNA platform to send GCM messages to the devices your app is installed on.
Detailed instructions can be found at https://developers.google.com/cloud-messaging/android/client
Enable Google Services for Your App
On https://developers.google.com/cloud-messaging/android/client in step 2 you’ll find a link to creating the app in the Google Developers console.
Here you fill in the name of your app and the package name, as such:
The GCM API Key
The next step is to enable Cloud Messaging, and copy the Server API key, this will be used on the server (in this case, deltaDNA) that will send messages via GCM.
On the deltaDNA platform, navigate to the Manage Identity page (Setup > Manage Identity) and enter the API
Go to your deltaDNA game “setup-manage identity” and fill in this key as the API key for the Android configuration.
The Configuration File
Now all we need is the configuration file. This can be generated at the bottom of the page and is called google-service.json and will need to be put in the app module of your Android project.
Integrate GCM in Your App
And now for the most difficult part; we need to integrate GCM with the app.
Since Google has an extensive manual on how to implement GCM see https://developers.google.com/cloud-messaging/android/client on how to implement this.
GCM and deltaDNA
The following sequence diagram shows a simplified overview of how the registrationID is retrieved and sent to the deltaDNA platform.
In order to get you started with GCM in the deltaDNA platform you can use a demo app that is integrated with both deltaDNA and GCM. And since GCM only sends a message to the app and not show a notification this is implemented as well.
See https://github.com/deltaDNA/android-notifications-example for the demo application, at the moment this is integrated with a deltaDNA account and a GCM project.
In order to use this with your accounts; replace the google-services.json file and the SDK initialization code in the MainActivity.java file to use your URL’s and environment key for deltaDNA.