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)
1pubnub.addPushNotificationsOnChannels()
2 .pushType(PNPushType)
3 .channels(List<String>)
4 .deviceId(String)
5 .topic(String)
6 .environment(PNPushEnvironment)
pushTyperequired#- Push notification type. Accepted values:
PNPushType.FCM(Firebase Cloud Messaging),PNPushType.APNS2(Apple Push Notification service v2). channelsrequired#- Channels to enable for push notifications.
deviceIdrequired#- Device ID (push token).
topic#- APNs topic (bundle identifier). Required for APNS2.
environment#- APNs environment. Accepted values:
PNPushEnvironment.DEVELOPMENT,PNPushEnvironment.PRODUCTION. Required for APNS2. async#Consumerof aResultof typePNPushAddChannelResult.
Sample code
Add device to channel
1
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)
1pubnub.auditPushChannelProvisions()
2 .pushType(PNPushType)
3 .deviceId(String)
4 .topic(String)
5 .environment(PNPushEnvironment)
pushTyperequired#- Push notification type. Accepted values:
PNPushType.FCM,PNPushType.APNS2. deviceIdrequired#- Device ID (push token).
topic#- APNs topic (bundle identifier). Required for APNS2.
environment#- APNs environment. Accepted values:
PNPushEnvironment.DEVELOPMENT,PNPushEnvironment.PRODUCTION. Required for APNS2. async#Consumerof aResultof typePNPushListProvisionsResult.
Sample code
List channels for device
1
Returns
Returns PNPushListProvisionsResult with:
getChannels()#- 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)
1pubnub.removePushNotificationsFromChannels()
2 .pushType(PNPushType)
3 .deviceId(String)
4 .topic(String)
5 .environment(PNPushEnvironment)
pushTyperequired#- Push notification type. Accepted values:
PNPushType.FCM,PNPushType.APNS2. channelsrequired#- Channels to disable for push notifications.
deviceIdrequired#- Device ID (push token).
topic#- APNs topic (bundle identifier). Required for APNS2.
environment#- APNs environment. Accepted values:
PNPushEnvironment.DEVELOPMENT,PNPushEnvironment.PRODUCTION. Required for APNS2. async#Consumerof aResultof typePNPushRemoveChannelResult.
Sample code
Remove device from channel
1
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)
1pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
2 .pushType(PNPushType)
3 .deviceId(String)
4 .topic(String)
5 .environment(PNPushEnvironment)
pushTyperequired#- Push notification type. Accepted values:
PNPushType.FCM,PNPushType.APNS2. deviceIdrequired#- Device ID (push token).
topic#- APNs topic (bundle identifier). Required for APNS2.
environment#- APNs environment. Accepted values:
PNPushEnvironment.DEVELOPMENT,PNPushEnvironment.PRODUCTION. Required for APNS2. async#Consumerof aResultof typePNPushRemoveAllChannelsResult.
Sample code
Remove all mobile push notifications
1
Returns
No payload is returned. Check result.isFailure() on error or handle exceptions via result.onFailure(...).