Skip to content

Example: Target Individual Devices

Synchronous Publish

using BackendlessAPI;
using BackendlessAPI.Messaging;
Backendless.InitApp( appId, secretKey, version ); // where to get the values for the InitApp call

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PushSinglecast.Add( TARGET_DEVICE_ID );

PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "android-ticker-text", "You just got a push notification!" );
publishOptions.AddHeader( "android-content-title", "This is a notification title" );
publishOptions.AddHeader( "android-content-text", "Push Notifications are cool" );

MessageStatus status = Backendless.Messaging.Publish( "Hi Android!", publishOptions, deliveryOptions );
System.Console.WriteLine( "Message published. Message ID - " + status.MessageId + ". Message Status - " + status.Status );

if( status.Status == PublishStatusEnum.FAILED )
  System.Console.WriteLine( "Message publish failed with error " + status.ErrorMessage );

Asynchronous Publish

using BackendlessAPI;
using BackendlessAPI.Messaging;
Backendless.InitApp( appId, secretKey, version ); // where to get the values for the InitApp call

AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
        result =>
        {
          System.Console.WriteLine( "Message published. Message ID - " + result.MessageId + ". Message Status - " + result.Status );

          if( result.Status == PublishStatusEnum.FAILED )
            System.Console.WriteLine( "Message publish failed with error " + result.ErrorMessage );
        },
        fault =>
        {
          System.Console.WriteLine( "Error - " + fault );
        } );

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PushSinglecast.Add( TARGET_DEVICE_ID );

PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "android-ticker-text", "You just got a push notification!" );
publishOptions.AddHeader( "android-content-title", "This is a notification title" );
publishOptions.AddHeader( "android-content-text", "Push Notifications are cool" );

Backendless.Messaging.Publish("Hi Android!", publishOptions, deliveryOptions, callback );

Codeless Reference

The example below publishes the message to the "default" channel. This message is delivered only three devices specified in the device ids property.

push_target_individual_os_devices_1

For a detailed description of the Codeless block, refer to the Push With API topic of this guide.