public class Push

  1. Object
  2. Push
Utility class for sending a push message to a different device through the Codename One push servers.

Fields

public static final String GOOGLE_PUSH_KEY = "googlePlay"Key for the hashtable argument when pushing to the google play store

Constructors

public Push(String token, String body, String... deviceKeys)Creates a new push notification.

Methods

public static boolean sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static boolean sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static void sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static void sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static String getDeviceKey()Deprecated Returns the push device key if the device was previously successfully registered for push otherwise returns null
public static String getPushKey()Returns the push device key if the device was previously successfully registered for push otherwise returns null
public static void subscribeToTopic(String topic)Subscribes this device to a push topic.
public static void unsubscribeFromTopic(String topic)Unsubscribes this device from a previously subscribed push topic.
public static boolean sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static boolean sendPushMessage(String token, String body, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, int pushType, String... deviceKey)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static boolean sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static void sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public static void sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)Deprecated Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.
public Push gcmAuth(String googleAuthKey)Sets authentication for GMS (Android and Chrome)
public Push apnsAuth(String iosCertificateURL, String iosCertificatePassword, boolean production)Sets authentication for APNS (iOS)
public Push wnsAuth(String wnsSID, String wnsClientSecret)Sets authenticaton for WNS (Windows 10/UWP)
public Push pushType(int pushType)Sets the type of push to use.
public boolean send()Sends push message.
public void sendAsync()Sends push message asynchronously.

Inherited methods

Field details

GOOGLE_PUSH_KEY

public static final String GOOGLE_PUSH_KEY = "googlePlay"
Key for the hashtable argument when pushing to the google play store

Constructor details

Push

public Push(String token, String body, String... deviceKeys)
Creates a new push notification.

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
deviceKeys String...
Device keys when sending to specific devices.

Method details

sendPushMessage

public static boolean sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
Deprecated. this method sends a push using the old push servers which will be retired, you need to switch to the equivalent method that accepts a push token
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.

Parameters

body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate

Returns

true if the message reached the Codename One server successfully, this makes no guarantee of delivery.

sendPushMessage

public static boolean sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
Deprecated. this method sends a push using the old push servers which will be retired, you need to switch to the equivalent method that accepts a push token
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.

Parameters

body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
bbUrl String
the URL to which the push should be submitted when sending a blackberry push for evaluation use https://pushapi.eval.blackberry.com for production you will need to apply at https://cp310.pushapi.na.blackberry.com
bbApp String
the application id to authenticate on push for RIM devices
bbPass String
the application password credentials authenticate on push for RIM devices
bbPort String
the port of the blackberry push

Returns

true if the message reached the Codename One server successfully, this makes no guarantee of delivery.

sendPushMessageAsync

public static void sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
Deprecated. this method sends a push using the old push servers which will be retired, you need to switch to the equivalent method that accepts a push token
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.

Parameters

body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate

sendPushMessageAsync

public static void sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
Deprecated. this method sends a push using the old push servers which will be retired, you need to switch to the equivalent method that accepts a push token
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices.

Parameters

body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
bbUrl String
the URL to which the push should be submitted when sending a blackberry push for evaluation use https://pushapi.eval.blackberry.com for production you will need to apply at https://cp310.pushapi.na.blackberry.com
bbApp String
the application id to authenticate on push for RIM devices
bbPass String
the application password credentials authenticate on push for RIM devices
bbPort String
the port of the blackberry push

getDeviceKey

public static String getDeviceKey()
Deprecated. this method sends a push using the old push servers which will be retired, you need to switch to getPushKey()
Returns the push device key if the device was previously successfully registered for push otherwise returns null

Returns

the device key that can be used to push to this specific device.

getPushKey

public static String getPushKey()
Returns the push device key if the device was previously successfully registered for push otherwise returns null

Returns

the device key that can be used to push to this specific device.

subscribeToTopic

public static void subscribeToTopic(String topic)

Subscribes this device to a push topic. Topics are a fan-out mechanism: a single server-side push to a topic is delivered to every device subscribed to it, without the server needing to track individual device keys.

On Android this maps to Firebase Cloud Messaging topics. On iOS, where the stock push transport is raw APNs which has no native topic concept, this is a no-op and topic fan-out must be performed server side; a warning is logged.

Parameters

topic String
the topic name

unsubscribeFromTopic

public static void unsubscribeFromTopic(String topic)

Unsubscribes this device from a previously subscribed push topic.

On Android this maps to Firebase Cloud Messaging topics. On iOS this is a no-op; a warning is logged.

Parameters

topic String
the topic name

sendPushMessage

public static boolean sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
Deprecated. Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices. This method uses the new push servers

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
deviceKey String
the device key that will receive the push message (can’t be null!)
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate

Returns

true if the message reached the Codename One server successfully, this makes no guarantee of delivery.

sendPushMessage

public static boolean sendPushMessage(String token, String body, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, int pushType, String... deviceKey)
Deprecated. Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices. This method uses the new push servers

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
pushType int
the type for the push in the server, this is useful for sending hidden pushes (type 2) should default to 0 or 1
deviceKey String...
set of devices that should receive the push

Returns

true if the message reached the Codename One server successfully, this makes no guarantee of delivery.

sendPushMessage

public static boolean sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
Deprecated. Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices. This method uses the new push servers

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
bbUrl String
the URL to which the push should be submitted when sending a blackberry push for evaluation use https://pushapi.eval.blackberry.com for production you will need to apply at https://cp310.pushapi.na.blackberry.com
bbApp String
the application id to authenticate on push for RIM devices
bbPass String
the application password credentials authenticate on push for RIM devices
bbPort String
the port of the blackberry push

Returns

true if the message reached the Codename One server successfully, this makes no guarantee of delivery.

sendPushMessageAsync

public static void sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
Deprecated. Please use new builder syntax with #sendAsync() which includes parameters for new platforms such as UWP.
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices. This method uses the new push servers

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate

sendPushMessageAsync

public static void sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
Deprecated. Please use new builder syntax with #sendAsync() which includes parameters for new platforms such as UWP.
Sends a push message and returns true if server delivery succeeded, notice that the push message isn’t guaranteed to reach all devices. This method uses the new push servers

Parameters

token String
the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app
body String
the body of the message
deviceKey String
an optional parameter (can be null) when sending to a specific device
production boolean
whether pushing to production or test/sandbox environment
googleAuthKey String
authorization key from the google play store
iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
bbUrl String
the URL to which the push should be submitted when sending a blackberry push for evaluation use https://pushapi.eval.blackberry.com for production you will need to apply at https://cp310.pushapi.na.blackberry.com
bbApp String
the application id to authenticate on push for RIM devices
bbPass String
the application password credentials authenticate on push for RIM devices
bbPort String
the port of the blackberry push

gcmAuth

public Push gcmAuth(String googleAuthKey)
Sets authentication for GMS (Android and Chrome)

Parameters

googleAuthKey String
authorization key from the google play store

Returns

self for chaining

apnsAuth

public Push apnsAuth(String iosCertificateURL, String iosCertificatePassword, boolean production)
Sets authentication for APNS (iOS)

Parameters

iosCertificateURL String
a URL where you host the iOS certificate for this applications push capabilities.
iosCertificatePassword String
the password for the push certificate
production boolean
True if this is a production certificate. False if this is a development certificate.

Returns

Self for chaining

wnsAuth

public Push wnsAuth(String wnsSID, String wnsClientSecret)
Sets authenticaton for WNS (Windows 10/UWP)

Parameters

wnsSID String
The SID from the Windows store.
wnsClientSecret String
The client secret from the windows store

Returns

self for chaining.

pushType

public Push pushType(int pushType)
Sets the type of push to use. See developer guide for details of different push types. Default is 1

Returns

Self for chaining.

send

public boolean send()
Sends push message.

Returns

True if the request was successful.

sendAsync

public void sendAsync()
Sends push message asynchronously.