Push Notifications

To create a Google API project:

  1. Open the Google Cloud Console.
  2. If you haven't created an API project yet, click Create Project.
  3. Supply a project name and click Create.
  4. Once the project has been created, a page appears that displays your project ID and project number. For example, Project Number: 670330094152.
  5. Copy down your project number. You will use it later on as the GCM sender ID.


Enabling the GCM Service

  1. In the sidebar on the left, select APIs & auth.
  2. In the displayed list of APIs, turn the Google Cloud Messaging for Android toggle to ON.


Obtaining an API Key

  1. In the sidebar on the left, select APIs & auth > Credentials.
  2. Under Public API access, click Create new key.
  3. In the Create a new key dialog, click Server key.
  4. In the resulting configuration dialog, supply your server's IP address. For testing purposes, you can use0.0.0.0/0.
  5. Click Create.
  6. In the refreshed page, copy the API key. You will need the API key later on to perform authentication in your application server.
  7. Note: If you need to rotate the key, click Regenerate key. A new key will be created. If you think the key has been compromised and you want to delete it immediately, click Delete.


Google Developer Console.

  1.  Open the Google APIs Console page
  2. If you have never created a project before, the page will prompt you to create one

In other case, the Dashboard page is displayed for the last project previously created. You can use that project or create a new one in the API Project -> Create Project menu

In any case, take note of the value of Project Number present on the screen This value will be used later when configuring the Smart Devices Main Object in GeneXus to enable it to receive notifications (Sender ID property).


3. Enable GCM Service (if it is not) in the APIs option of the APIs & auth menu.


That is all. We are now ready to use Push Notifications.

You can implement your own server-side for sending and managing push notification. Following guide will describe all necessary steps, and you also will find push server PHP example script inside the plugin. But Android Native offers few alternatives as well. You can use one of he supported 3-rd party push notification services:



To get the device registration Id you should call




After this, you can send the registration Id  to your backend.


To find out if the push notification was received, you can use



it will trigger ActionCouldMessageLoaded  event. And you can get the message using getter:



See the code snippet bellow:

GoogleCloudMessageService.ActionCouldMessageLoaded += OnMessageLoaded;

private void OnMessageLoaded(string lastMessage) {
    GoogleCloudMessageService.ActionCouldMessageLoaded -= OnMessageLoaded;
	AndroidMessage.Create("Message Loaded", "Last GCM Message: " + GoogleCloudMessageService.instance.lastMessage);


If you want to remove last message info. you can use RemoveLastMessageInfo method as showed bellow:



Example of server code can be found at:



You fill found testgcm.php example file inside. Which will demonstrate how to send push notification using PHP.


Replace with this key with your own API key:

// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOU_API_KEY' );


And add your device id:

$registrationIds = array("YOUR_DEVICE_REGISTRATION_ID_HERE");


Then you can use console to run testgcm.php script for sending push notification to  your device:

 php <path_to_gcm.php>

Or any other way to run PHP script.

Push Notification Data Format

For now, Android Native plugin supports next notification data format.

'title'         => '_title_string_',
'subtitle'   => '_subtitle_string_',
'alert'        => '_message_string_',
'json'        => '_json_formatted_data_string_'

If you are using testgcm.php script for push notifications support in you project, you have to setup next data bundle:

// prep the bundle
$msg = array
    'title'         => 'This is a title. title',
    'subtitle'   => 'This is a subtitle. subtitle',
    'alert'        => 'here is a message. message',
    'json'        => '{"big_picture_url": "http://www.hd-tecnologia.com/imagenes/articulos/2015/03/Unity-5.jpg",
                        "string_extra": "100000583627394",
                        "string_value": "value",
                        "string_key": "key",
                        "is_public": true,
                        "item_type_id": 4,
                        "numeric_extra": 0}'

$fields = array
    'registration_ids'  => $registrationIds,
    'data'              => $msg

You can provide any JSON data you need for your particular case.

One important thing: big_picture_url field is reserved for Big-Picture Notification Style. If you don't use Big-Picture Notification Style, just leave this field string.Empty, but DON'T remove from JSON data. All other fields added as an example. What data fields and fields amounts are up to you as a developer.


Using Push Notifications

First, you have to Setup Push Notifications Settings in Inspector.

Next Settings available:

  • Show in a foreground. 
  • Replace old notification with the new one.
  • Disable/Enable Vibration 
  • Setup Notification Icon.
  • Setup Notification Sound.
  • Sender Id for Google Push Service.
  • Choose Push Services. 


If you don't set up Push Notification settings in the inspector, then default settings will be applied.

To submit PushNotifications Settings just call GoogleCloudMessageService.Instance.Init(); method at the start of your Application.



Manifest Requirements

  • The android.permission.GET_ACCOUNTS permission as GCM requires a Google account (necessary only if  the device is running a version lower than Android 4.0.4)
  • The android.permission.WAKE_LOCK permission so the application can keep the processor from sleeping when a message is received. Optionalâuse only if the app wants to keep the device from sleeping.
  • An applicationPackage + ".permission.C2D_MESSAGE" permission to prevent other Android applications from registering and receiving the Android application's messages. The permission name must exactly match this patternâotherwise the Android application will not receive the messages.

Here are excerpts from a sample manifest that supports GCM:

<manifest package="com.example.gcm" ...>

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <permission android:name="com.example.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

    <application ...>
            android:permission="com.google.android.c2dm.permission.SEND" >
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example.gcm" />
        <service android:name="com.androidnative.gcm.GcmIntentService" />



Warning: Plugin will add all necessary receivers and permissions automatically, but since permissions names is depends from your app bundle id name, if you will change application bundle id with the Unity Project settings, it will triggers adding new permission to your manifest, so you need to clean up manually permissions which use your old bundle id.

Check if  Notifications are ON?

Assuming you are referring to Google Cloud Messaging (since you are using the android and push-notification tag), there are no general settings used to enable/disable the GCM service (unlike the Apple Push Notifications service for iOS devices, not mix with the general notifications app settings).

When you install an app, if the app uses Google Cloud Messaging, it will be listed in the list of permissions that this app requires in order to work. By choosing to install the app you allow it to send push notifications to you.

That said, in order for the app to actually receive GCM messages, your app must programmatically register to the GCM service. You can do that in any place you wish within your app, and you can create an app settings screen in which the user can enable/disable GCM (which would trigger registration/unregistration to/from GCM). Your app can contain a persistent store that would hold the registration ID you receive upon registration to GCM, and you can use that store to determine if your app in registered to GCM.

You can ask your user to turn it on if the app is already running (if you have some code that does that). If it's not running and the app is not registered for GCM on that device, your server can't send GCM messages to it.

If you want to overcome that obstacle, you can register to GCM automatically (when the app is first launched). Then you can send messages to the app whenever you wish. If you still want to let the user decide whether they want to see those notifications, you can have a flag in your app settings that enables/disables the UI notification that you create as a result of an incoming GCM message. The GCM service will always be enabled, but unless the user chooses to view the notifications, you app won't display anything when a GCM message arrives.

Example Scenes

  • Assets/Extensions/AndroidNative/xExample/Scenes/Other/Notifications