Developer Guide - Mozgoid/unity-gcm GitHub Wiki

Installation

  1. Download unitypackage from here
  2. Import unity-gcm.unitypackage into your Unity project
  3. Open Assets/Plugins/Android/AndroidManifest.xml and replace INPUT_YOUR_BUNDLE_IDENTIFIER with your bundle identifier
    • The default bundle identifier "com.Company.ProductName" is not available!
  4. Get Project Number in Google API Console
  5. 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);

Show notification view in Android status bar

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.

Run sample scenes

Client side

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.

Server side

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.

FAQ

Q. I have already used Assets/Plugins/Android/AndroidManifest.xml in my project

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 -->
⚠️ **GitHub.com Fallback** ⚠️