Class Push

java.lang.Object
com.codename1.push.Push

public class Push extends Object
Utility class for sending a push message to a different device through the Codename One push servers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Key for the hashtable argument when pushing to the google play store
  • Constructor Summary

    Constructors
    Constructor
    Description
    Push(String token, String body, String... deviceKeys)
    Creates a new push notification.
  • Method Summary

    Modifier and Type
    Method
    Description
    apnsAuth(String iosCertificateURL, String iosCertificatePassword, boolean production)
    Sets authentication for APNS (iOS)
    gcmAuth(String googleAuthKey)
    Sets authentication for GMS (Android and Chrome)
    static String
    Returns the push device key if the device was previously successfully registered for push otherwise returns null
    static String
    Returns the push device key if the device was previously successfully registered for push otherwise returns null
    pushType(int pushType)
    Sets the type of push to use.
    boolean
    Sends push message.
    void
    Sends push message asynchronously.
    static boolean
    sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static boolean
    sendPushMessage(String token, String body, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, int pushType, String... deviceKey)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static boolean
    sendPushMessage(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static boolean
    sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    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)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static void
    sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static void
    sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, String bbUrl, String bbApp, String bbPass, String bbPort)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    static void
    sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    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)
    Sends a push message and returns true if server delivery succeeded, notice that the push message isn't guaranteed to reach all devices.
    wnsAuth(String wnsSID, String wnsClientSecret)
    Sets authenticaton for WNS (Windows 10/UWP)

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GOOGLE_PUSH_KEY

      public static final String GOOGLE_PUSH_KEY
      Key for the hashtable argument when pushing to the google play store
      See Also:
  • Constructor Details

    • Push

      public Push(String token, String body, String... deviceKeys)

      Creates a new push notification.

      Parameters
      • token: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • deviceKeys: 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)

      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: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      Returns
      Returns:

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

      Deprecated
    • 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)

      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: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • bbUrl: @param bbUrl 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: the application id to authenticate on push for RIM devices

      • bbPass: the application password credentials authenticate on push for RIM devices

      • bbPort: the port of the blackberry push

      Returns
      Returns:

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

      Deprecated
    • sendPushMessageAsync

      public static void sendPushMessageAsync(String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)

      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: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      Deprecated
    • 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)

      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: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • bbUrl: @param bbUrl 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: the application id to authenticate on push for RIM devices

      • bbPass: the application password credentials authenticate on push for RIM devices

      • bbPort: the port of the blackberry push

      Deprecated
    • getDeviceKey

      public static String getDeviceKey()

      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.

      Deprecated
    • 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.

    • sendPushMessage

      public static boolean sendPushMessage(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)

      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: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • deviceKey: the device key that will receive the push message (can't be null!)

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      Returns
      Returns:

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

      Deprecated

      Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.

    • sendPushMessage

      public static boolean sendPushMessage(String token, String body, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword, int pushType, String... deviceKey)

      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: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • pushType: @param pushType the type for the push in the server, this is useful for sending hidden pushes (type 2) should default to 0 or 1

      • deviceKey: set of devices that should receive the push

      Returns
      Returns:

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

      Deprecated

      Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.

    • 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)

      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: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • bbUrl: @param bbUrl 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: the application id to authenticate on push for RIM devices

      • bbPass: the application password credentials authenticate on push for RIM devices

      • bbPort: the port of the blackberry push

      Returns
      Returns:

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

      Deprecated

      Please use new builder syntax with #send() which includes parameters for new platforms such as UWP.

    • sendPushMessageAsync

      public static void sendPushMessageAsync(String token, String body, String deviceKey, boolean production, String googleAuthKey, String iosCertificateURL, String iosCertificatePassword)

      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: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      Deprecated

      Please use new builder syntax with #sendAsync() which includes parameters for new platforms such as UWP.

    • 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)

      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: @param token the authorization token from the account settings in the CodenameOne website, this is used to associate push quotas with your app

      • body: the body of the message

      • deviceKey: an optional parameter (can be null) when sending to a specific device

      • production: whether pushing to production or test/sandbox environment

      • googleAuthKey: authorization key from the google play store

      • iosCertificateURL: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • bbUrl: @param bbUrl 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: the application id to authenticate on push for RIM devices

      • bbPass: the application password credentials authenticate on push for RIM devices

      • bbPort: the port of the blackberry push

      Deprecated

      Please use new builder syntax with #sendAsync() which includes parameters for new platforms such as UWP.

    • gcmAuth

      public Push gcmAuth(String googleAuthKey)

      Sets authentication for GMS (Android and Chrome)

      Parameters
      • googleAuthKey: 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: a URL where you host the iOS certificate for this applications push capabilities.

      • iosCertificatePassword: the password for the push certificate

      • production: 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: The SID from the Windows store.

      • wnsClientSecret: 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

      Parameters
      • pushType
      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.