Mobile Push Notifications API for 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.

The Mobile Push Notifications feature connects native PubNub publishing to third-party push services. Supported services include Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

To learn more, read about Mobile Push Notifications.

Add a device to a push notifications channel

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Enable mobile push notifications on a set of channels.

Method(s)

pubnub.addPushNotificationsOnChannels()
.pushType(PNPushType)
.channels(List<String>)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
* required
ParameterDescription
pushType *
Type: PNPushType
Accepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
channels *
Type: List<String>
Channels to enable for push notifications.
deviceId *
Type: String
Device ID (push token).
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment (APNS2).
async
Type: Consumer<Result>
Consumer of a Result of type PNPushAddChannelResult.

Sample code

Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

Add device to channel


Returns

No payload is returned. Check result.isSuccess() on the result object.

List push notifications channels for a device

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Get all channels with push notifications for the specified push token.

Method(s)

pubnub.auditPushChannelProvisions()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
* required
ParameterDescription
pushType *
Type: PNPushType
Accepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
deviceId *
Type: String
Device ID (push token).
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment (APNS2).
async
Type: Consumer<Result>
Consumer of a Result of type PNPushListProvisionsResult.

Sample code

List channels for device


Returns

Returns PNPushListProvisionsResult with:

MethodDescription
getChannels()
Type: List<String>
Channels associated with push notifications.

Remove a device from push notifications channels

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Disable push notifications on selected channels.

Method(s)

pubnub.removePushNotificationsFromChannels()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
* required
ParameterDescription
pushType *
Type: PNPushType
Accepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
channels *
Type: List<String>
Channels to disable for push notifications.
deviceId *
Type: String
Device ID (push token).
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment (APNS2).
async
Type: Consumer<Result>
Consumer of a Result of type PNPushRemoveChannelResult.

Sample code

Remove device from channel


Returns

No payload is returned. Check result.isFailure() on error or handle exceptions via result.onFailure(...).

Remove a device from all push notifications channels

Requires Mobile Push Notifications add-on

Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.

Disable push notifications from all channels registered for the specified push token.

Method(s)

pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
.pushType(PNPushType)
.deviceId(String)
.topic(String)
.environment(PNPushEnvironment)
* required
ParameterDescription
pushType *
Type: PNPushType
Accepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS, PNPushType.APNS2
deviceId *
Type: String
Device ID (push token).
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment (APNS2).
async
Type: Consumer<Result>
Consumer of a Result of type PNPushRemoveAllChannelsResult.

Sample code

Remove all mobile push notifications


Returns

No payload is returned. Check result.isFailure() on error or handle exceptions via result.onFailure(...).

Last updated on