Share via


gcm object

 

Enables you to send push notifications to an Android app from Microsoft Azure Mobile Services server scripts using Azure Notification Hubs.

Methods

  • createNativeRegistration(gcmRegistrationId, tags, options, callback)
    Creates a native GCM registration.

    Parameters

    Name

    Type

    Argument

    Description

    gcmRegistrationId

    string

    The GCM registration ID.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createOrUpdateNativeRegistration(registrationId, gcmRegistrationId, tags, options, callback)
    Creates or updates a native GCM registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    gcmRegistrationId

    string

    The GCM registration ID.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createOrUpdateTemplateRegistration(registrationId, gcmRegistrationId, template, options, callback)
    Creates or updates a template registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    gcmRegistrationId

    string

    The GCM registration ID.

    template

    string | array

    The JSON or string payload for the message.

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createTemplateRegistration(gcmRegistrationId, tags, template, options, callback)
    Creates a template registration.

    Parameters

    Name

    Type

    Argument

    Description

    gcmRegistrationId

    string

    The GCM registration ID.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    template

    string | array

    The JSON or string payload for the message.

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • listRegistrationsByGcmRegistrationId(gcmRegistrationId, options, callback)
    Retrieves a registration by GCM registration ID.

    Parameters

    Name

    Type

    Argument

    Description

    gcmRegistrationId

    string

    The GCM registration ID.

    options

    object

    <optional>

    The request options or callback function. Additional properties are passed as headers.

    Name

    Type

    Argument

    Description

    top

    object

    <optional>

    Specifies the maximum number of registration to obtain from the call.

    skip

    object

    <optional>

    Specifies the number of registrations to skip in the call.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • send(tags, payload, callback)
    Sends an GCM notification.

    Parameters

    Name

    Type

    Description

    tags

    string

    A single tag or tag expression. When null, the message is sent to all template registrations.

    payload

    object | string

    The message's JSON or string payload.

    payload

    object | string

    The template message payload.

    callback

    object

    A JSON object that specifies the success and error callback functions.

  • updateTemplateRegistration(registrationId, gcmRegistrationId, template, options, callback)
    Updates an existing template registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    gcmRegistrationId

    string

    The GCM registration ID.

    template

    object | string

    The message's JSON or string payload.

    options

    object

    <optional>

    The request options.

    callback

    object

    A JSON object that specifies the success and error callback functions.

Remarks

For an example of how to send push notifications from your mobile service to an Android app, see Add push notifications to your Mobile Services app.

The gcm object is obtained from the push object in a server script. For a complete example, see Get started with push notifications.

Example

The following example calls the send method to send a text notification to a specific device when a new item is inserted into a table.

function insert(item, user, request) {
// Define a payload for the Google Cloud Messaging toast notification.
var payload = 
    '{"data":{"message" : ' + item.text + ' }}';

request.execute({
    success: function() {
        // If the insert succeeds, send a notification.
        push.gcm.send(null, payload, {
            success: function(pushResponse) {
                console.log("Sent push:", pushResponse, payload);
                request.respond();
                },              
            error: function (pushResponse) {
                console.log("Error Sending push:", pushResponse);
                request.respond(500, { error: pushResponse });
                }
            });
        },
    error: function(err) {
        console.log("request.execute error", err)
        request.respond();
    }
  });
}

See Also

Get started with push notifications
Mobile Services JavaScript (Node.js) backend library
apns object
mpns object
wns object