Mobile Push Notifications API for PubNub Java SDK

Breaking changes since 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. These changes can impact applications built with previous versions 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

note
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)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
channelsList<String>YesAdd mobile push notifications on the specified channels.
deviceIdStringYesThe device ID (token) to associate with mobile push notifications.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2.
environmentPNPushEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2).
asyncConsumer<Result>OptionalConsumer 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

note
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)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
deviceIdStringYesThe device ID (token) to associate with mobile push notifications.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2.
environmentPNPushEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2).
asyncConsumer<Result>OptionalConsumer 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:

MethodTypeDescription
getChannels()List<String>List of channels associated for mobile push notifications.

Remove Device From Channel

note
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)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
channelsList<String>YesAdd mobile push notifications on the specified channels.
deviceIdStringYesThe device ID (token) to associate with mobile push notifications.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2.
environmentPNPushEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2).
asyncConsumer<Result>OptionalConsumer 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

note
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)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
deviceIdStringYesThe device ID (token) to associate with mobile push notifications.
topicStringOptionalNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushType set to APNS2.
environmentPNPushEnvironmentOptionalEnvironment within which device should manage list of channels with enabled notifications (works only if pushType set to APNS2).
asyncConsumer<Result>OptionalConsumer 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().

Last updated on