Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class PushTarget
- Object
- 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"APNS
public static final String APNS = "apns"HUAWEI
public static final String HUAWEI = "huawei"WNS
public static final String WNS = "wns"WEB
public static final String WEB = "web"Method details
of
public static PushTarget of(String provider, String token)token on provider.Parameters
providerString- the provider id:
fcm,apns,huawei,wnsorweb, or one of the aliasesgcm,iosandhms, in any case tokenString- the provider’s token for the device
Returns
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
deviceKeyString- the key the device registered
Returns
Throws
IllegalArgumentException- if the key doesn’t have that form, names an unknown provider, or has no token
getProvider
public String getProvider()Returns
fcm, apns, huawei, wns and webgetToken
public String getToken()Returns
toString
public String toString()