In case you missed it, we recently announced a new version of our Kii Unity SDK that supports push notifications when deploying to Android and iOS. This post focuses on how to set up your Unity game so Android players can receive push notifications. The steps for iOS are pretty similar. Big difference is while iOS uses Apple Push Notification Service (APNS), Android uses Google Cloud Messaging (GCM).
Set up the backend
Your first move is to tell Kii and Google you want to use push notifications in your game. It takes 5 detailed steps but they’re not hard.
- Create an application in your Kii developer console
- Install the Kii Unity libraries in your game
- Initialize the Kii backend by providing app id and key from the game
- Set up your app in Google for push
- Configure your game in the Kii developer console with Google’s GCM API key
Update your game
Our latest Unity SDK (v1.8.2+) has a new file called
KiiPushPlugin.unitypackage that provides all the push functionality on the Unity side. To import it into your Unity game, double click on it while Unity is open. New files are added to the Plugins directory of your project. (You can uncheck the iOS specific files for this demo if you want to save space.)
Along with low-level push files, you’ll find a
Plugins/KiiPushPlugin.cs file that provides the interface for push at the Unity level. Open
Plugins/Android/AndroidManifest.xml and replace any instance of
with the package name you specified in the Unity Build Settings for Android.
Important: when editing the manifest don’t touch the line
KiiPushPlugin.cs by attaching it to a game object (e.g. attach it to the same object you used to initialize Kii via
KiiInitializeBehavior). Then fill in the Sender ID public variable (only for Android) with the app id assigned to you by Google (Google apis console -> Dashboard -> Project ID).
Next you need some code on the Unity side to handle the push notifications. You could use something like this:
Test it out
Let’s try to send a direct push message from developer.kii.com to a logged in game player. In your console go to the Push section of you project and click the “New Message” button. Create a message like this:
While a player is in the game and you’re signed in, click “Send…” The URL will open. Success!
Summing it all up, here are the steps to adding push notifications to your Android game with the Kii Unity SDK:
- Import contents of
KiiPushPlugin.unitypackageinto your Unity game
- Replace package name in
- Create an empty GameObject and attach the
KiiPushPlugin.csand fill in the Sender ID
- Add something like the code above to handle push notifications (
To help you get started even faster, we’ve put together this source code of a simple game already set up to support push on Android.