Note: Setting up Android push notifications for the first time? Instead of GCM, you may want to check out Google’s Firebase Cloud Messages.
In this tutorial we walk you through the steps to configure Google Cloud Messaging (GCM) with brainCloud.
- Must have a Google developer account
- Must have created an app on the Google developer console site
- Must have entered appropriate Google information in “Core App Info | Application IDs” seciont of the brainCloud portal
Create GCM API key for brainCloud
Enable the GCM API
- Navigate your browser to the Google developer console site
- Select your app
- Click the “APIs & auth | APIs” link on the left hand nav bar
- Select “Cloud Messaging for Android
- Enable the API
Create Public Access Key
- You should now have a server API key:
- Navigate to the brainCloud portal and enter this key in the Notifications | Settings for Google Play.
Enable GCM For Your App
In addition to the above steps, you will need to do the following in order for GCM to work in your app.
Link your Google Console game to Google Play
Apparently these two systems can’t talk to each other. Do the following to establish a link between the two systems.
- Navigate to the Google Play Developer site (play.google.com/apps/publish)
- Click Game Services in left hand navigation bar
- Click Add New Game button on top right
- Fill in the appropriate info in the Add Game dialog making sure to select “I already use Google APIs in my game” and using the appropriate game (Hello World is probably *not* the correct game).
Registering GCM Notification Token With brainCloud
After Authenticating a user with brainCloud, you will want to Register their GCM notification token with brainCloud. Specifically you’ll want to call the BrainCloudPushNotifications.RegisterDeviceToken() and pass in the registration id. In order to get this registration id, follow these steps.
Note that this example assume you are working in Java on an Android device. For developers using Unity, follow the appropriate instructions available elsewhere.
- Find your “Sender Id” – the number which appears under your app’s name in the Game Services section of the Google Play developer site.
- This Sender Id is what you will need to pass to the GCM Java API to get a registration id. The code below shows how to retrieve the registration id:
- Once you have the registration id you will want to call BrainCloudPushNotifications.RegisterDeviceToken()
Other Google Configuration Stuff
A few other tasks remain to link credentials together etc.
Create OAuth Key
- In the Google Developer Console navigate to the “Apis & auth | Credentials” section
- Under the OAuth section click “Create new Client ID”
- Fill in the appropriate info
- Your Client ID should now available
Link Client ID to Google Play
- Navigate to the Google Play Developer Console
- Select Game Services for your app from left hand navigation bar
- Click “Linked Apps”
- Click “Android” button
- Enter the appropriate information for your app
- And finally, verify that your Client ID is linked in correctly
- Take a breath of fresh air, you are finally *done*!