Class PushTarget

java.lang.Object
com.codename1.backend.push.PushTarget

public final class PushTarget extends Object

One device to deliver a push to: the provider that owns the device and the token that provider issued for it.

The push service names five providers: fcm, apns, huawei, wns and web. A device reports its provider in older spellings too -- the app's PushSubscription.getTransportId() can answer gcm, ios or hms -- so of(String, String) accepts those and stores the service's name. A device key from the classic Push.getPushKey(), such as cn1-fcm-TOKEN, is read by fromDeviceKey(String).

toString() names the provider only. A token identifies one person's device, so it stays out of anything that might reach a log.

  • Field Details

  • Method Details

    • of

      public static PushTarget of(String provider, String token)
      A target for token on provider.
      Parameters:
      provider - the provider id: fcm, apns, huawei, wns or web, or one of the aliases gcm, ios and hms, in any case
      token - the provider's token for the device
      Returns:
      the target, with the provider in the service's spelling
      Throws:
      IllegalArgumentException - if the provider is unknown or the token is null or blank
    • fromDeviceKey

      public static PushTarget fromDeviceKey(String deviceKey)

      A target from a classic device key, cn1-<provider>-<token>, as the app's Push.getPushKey() reports it: cn1-fcm-..., cn1-gcm-..., cn1-ios-... or cn1-hms-....

      The prefix is removed and the provider normalized, so the result carries the bare token the provider issued.

      Parameters:
      deviceKey - the key the device registered
      Returns:
      the target
      Throws:
      IllegalArgumentException - if the key doesn't have that form, names an unknown provider, or has no token
    • getProvider

      public String getProvider()
      Returns:
      the provider, always one of fcm, apns, huawei, wns and web
    • getToken

      public String getToken()
      Returns:
      the provider's token for the device
    • toString

      public String toString()
      The provider only; the token is left out so a logged target identifies no device.
      Overrides:
      toString in class Object