Developer Guide - Mozgoid/unity-gcm GitHub Wiki
- Download unitypackage from here
- Import
unity-gcm.unitypackage
into your Unity project - Open
Assets/Plugins/Android/AndroidManifest.xml
and replaceINPUT_YOUR_BUNDLE_IDENTIFIER
with your bundle identifier- The default bundle identifier "com.Company.ProductName" is not available!
- Get Project Number in Google API Console
- Follow the Google's documentation
- Copy and paste the following code in your application's initialization
// Use this for initialization
void Start () {
// Create receiver game object
GCM.Initialize ();
// Set callbacks
GCM.SetErrorCallback ((string errorId) => {
Debug.Log ("Error!!! " + errorId);
});
GCM.SetMessageCallback ((Dictionary<string, object> table) => {
Debug.Log ("Message!!! " + table.ToString ());
});
GCM.SetRegisteredCallback ((string registrationId) => {
Debug.Log ("Registered!!! " + registrationId);
});
GCM.SetUnregisteredCallback ((string registrationId) => {
Debug.Log ("Unregistered!!! " + registrationId);
});
GCM.SetDeleteMessagesCallback ((int total) => {
Debug.Log ("DeleteMessages!!! " + total);
});
}
and call GCM.Register (string[] senderIds)
when you want to start GCM
string[] senderIds = {"Your Project Number"};
GCM.Register (senderIds);
By sending GCM with the defined fields, this plugin can show notification view in Android status bar (the notification will only be shown if all 3 fields are set).
- ticker
- content_text
- content_title
In detail, please see Ruby script to send GCM.
At first, follow Step 1...4 in the above Installation section.
There are sample scenes in Assets/GCM-Sample
folder. In order to run the scenes, you must create project at Google API Console and replace SENDER_IDS in Assets/GCM-Sample/MainScene.cs
with your Project Number.
Once the client application is launched and GCM is registered, you can send GCM to the registered devices.
For example, you can send GCM with Ruby script.
In order to use your AndroidManifest.xml, copy and paste the following two blocks into your AndroidManifest.xml (Of course replace INPUT_YOUR_BUNDLE_IDENTIFIER with your bundle identifier)
<!-- Android GCM Plugin -->
<permission android:name="INPUT_YOUR_BUNDLE_IDENTIFIER.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="INPUT_YOUR_BUNDLE_IDENTIFIER.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Android GCM Plugin -->
<!-- Android GCM Plugin -->
<receiver android:name="com.kskkbys.unitygcmplugin.UnityGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="INPUT_YOUR_BUNDLE_IDENTIFIER" />
</intent-filter>
</receiver>
<service android:name="com.kskkbys.unitygcmplugin.UnityGCMIntentService" />
<!-- Android GCM Plugin -->