Mobile Push Notifications API for PubNub Java SDK
Breaking changes in v9.0.0
PubNub Java SDK version 9.0.0 unifies the codebases for Java and Kotlin SDKs, introduces a new way of instantiating the PubNub client, and changes asynchronous API callbacks and emitted status events. These changes can impact applications built with previous versions (< 9.0.0
) of the Java SDK.
For more details about what has changed, refer to Java/Kotlin SDK migration guide.
Mobile Push Notifications feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).
By using the Mobile Push Notifications feature, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.
To learn more, read about Mobile Push Notifications.
Add Device to Channel
Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Enable mobile push notifications on provided set of channels.
Method(s)
To run Adding Device to Channel
you can use the following method(s) in the Java SDK:
pubnub.addPushNotificationsOnChannels()
.pushType(PNPushType)
.channels(List<String>)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Description |
---|---|---|---|
pushType | PNPushType | Yes | Accepted values: PNPushType.FCM , PNPushType.GCM , PNPushType.APNS , PNPushType.APNS2 |
channels | List<String> | Yes | Add mobile push notifications on the specified channels. |
deviceId | String | Yes | The device ID (token) to associate with mobile push notifications. |
topic | String | Optional | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2 . |
environment | PNPushEnvironment | Optional | Environment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2 ). |
async | Consumer<Result> | Optional | Consumer of a Result of type PNPushAddChannelResult . |
Basic Usage
Add Device to Channel
pubnub.addPushNotificationsOnChannels()
.pushType(PNPushType.FCM)
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.deviceId("googleDevice")
.async(result -> { /* check result */ });
Returns
The addPushNotificationsOnChannels()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the result.isSuccess()
.
List Channels For Device
Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Request for all channels on which push notification has been enabled using specified pushToken.
Method(s)
To run Listing Channels For Device
you can use the following method(s) in the Java SDK:
pubnub.auditPushChannelProvisions()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Description |
---|---|---|---|
pushType | PNPushType | Yes | Accepted values: PNPushType.FCM , PNPushType.GCM , PNPushType.APNS , PNPushType.APNS2 |
deviceId | String | Yes | The device ID (token) to associate with mobile push notifications. |
topic | String | Optional | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2 . |
environment | PNPushEnvironment | Optional | Environment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2 ). |
async | Consumer<Result> | Optional | Consumer of a Result of type PNPushListProvisionsResult . |
Basic Usage
List Channels For Device
pubnub.auditPushChannelProvisions()
.deviceId("googleDevice")
.pushType(PNPushType.FCM)
.async(result -> { /* check result */ });
Returns
The auditPushChannelProvisions()
operation returns a PNPushListProvisionsResult
which contains the following operations:
Method | Type | Description |
---|---|---|
getChannels() | List<String> | List of channels associated for mobile push notifications. |
Remove Device From Channel
Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Disable mobile push notifications on provided set of channels.
Method(s)
To run Removing Device From Channel
you can use the following method(s) in the Java SDK:
pubnub.removePushNotificationsFromChannels()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Description |
---|---|---|---|
pushType | PNPushType | Yes | Accepted values: PNPushType.FCM , PNPushType.GCM , PNPushType.APNS , PNPushType.APNS2 |
channels | List<String> | Yes | Add mobile push notifications on the specified channels. |
deviceId | String | Yes | The device ID (token) to associate with mobile push notifications. |
topic | String | Optional | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2 . |
environment | PNPushEnvironment | Optional | Environment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2 ). |
async | Consumer<Result> | Optional | Consumer of a Result of type PNPushRemoveChannelResult . |
Basic Usage
Remove Device From Channel
pubnub.removePushNotificationsFromChannels()
.deviceId("googleDevice")
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.pushType(PNPushType.FCM)
.async(result -> { /* check result */ });
Returns
The removePushNotificationsFromChannels()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError()
.
Remove all mobile push notifications
Requires Mobile Push Notifications add-on
This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
Disable mobile push notifications from all channels registered with the specified pushToken.
Method(s)
To run Remove all mobile push notifications
, you can use the following method(s) in the Java SDK:
pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Description |
---|---|---|---|
pushType | PNPushType | Yes | Accepted values: PNPushType.FCM , PNPushType.GCM , PNPushType.APNS , PNPushType.APNS2 |
deviceId | String | Yes | The device ID (token) to associate with mobile push notifications. |
topic | String | Optional | Notifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2 . |
environment | PNPushEnvironment | Optional | Environment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2 ). |
async | Consumer<Result> | Optional | Consumer of a Result of type PNPushRemoveAllChannelsResult . |
Basic Usage
Remove all mobile push notifications
pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
.deviceId("googleDevice")
.pushType(PNPushType.FCM)
.async(result -> { /* check result */ });
Returns
The removeAllPushNotificationsFromDeviceWithPushToken()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError()
.