Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class PushTarget

  1. Object
  2. PushTarget

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.

Fields

public static final String FCM = "fcm"Firebase Cloud Messaging, for Android.
public static final String APNS = "apns"Apple Push Notification service, for iOS.
public static final String HUAWEI = "huawei"Huawei Push Kit, for Huawei devices without Google services.
public static final String WNS = "wns"Windows Push Notification Services.
public static final String WEB = "web"Web Push, for browsers.

Methods

public static PushTarget of(String provider, String token)A target for token on provider.
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-....
public String getProvider()
public String getToken()
public String toString()The provider only; the token is left out so a logged target identifies no device.

Inherited methods

Field details

FCM

public static final String FCM = "fcm"
Firebase Cloud Messaging, for Android.

APNS

public static final String APNS = "apns"
Apple Push Notification service, for iOS.

HUAWEI

public static final String HUAWEI = "huawei"
Huawei Push Kit, for Huawei devices without Google services.

WNS

public static final String WNS = "wns"
Windows Push Notification Services.

WEB

public static final String WEB = "web"
Web Push, for browsers.

Method details

of

public static PushTarget of(String provider, String token)
A target for token on provider.

Parameters

provider String
the provider id: fcm, apns, huawei, wns or web, or one of the aliases gcm, ios and hms, in any case
token String
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 String
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.