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)
| Parameter | Description |
|---|---|
pushType *Type: PNPushType | Push notification type. Accepted values: PNPushType.FCM (Firebase Cloud Messaging), PNPushType.APNS2 (Apple Push Notification service v2). |
channels *Type: List<String> | Channels to enable for push notifications. |
deviceId *Type: String | Device ID (push token). |
topicType: String | APNs topic (bundle identifier). Required for APNS2. |
environmentType: PNPushEnvironment | APNs environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. Required for APNS2. |
asyncType: Consumer<Result> | Consumer of a Result of type PNPushAddChannelResult. |
Sample code
Reference 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)
| Parameter | Description |
|---|---|
pushType *Type: PNPushType | Push notification type. Accepted values: PNPushType.FCM, PNPushType.APNS2. |
deviceId *Type: String | Device ID (push token). |
topicType: String | APNs topic (bundle identifier). Required for APNS2. |
environmentType: PNPushEnvironment | APNs environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. Required for APNS2. |
asyncType: Consumer<Result> | Consumer of a Result of type PNPushListProvisionsResult. |
Sample code
List channels for device
1
Returns
Returns PNPushListProvisionsResult with:
| Method | Description |
|---|---|
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)
1pubnub.removePushNotificationsFromChannels()
2 .pushType(PNPushType)
3 .deviceId(String)
4 .topic(String)
5 .environment(PNPushEnvironment)
| Parameter | Description |
|---|---|
pushType *Type: PNPushType | Push notification type. Accepted values: PNPushType.FCM, PNPushType.APNS2. |
channels *Type: List<String> | Channels to disable for push notifications. |
deviceId *Type: String | Device ID (push token). |
topicType: String | APNs topic (bundle identifier). Required for APNS2. |
environmentType: PNPushEnvironment | APNs environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. Required for APNS2. |
asyncType: Consumer<Result> | Consumer of a Result of type PNPushRemoveChannelResult. |
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)
| Parameter | Description |
|---|---|
pushType *Type: PNPushType | Push notification type. Accepted values: PNPushType.FCM, PNPushType.APNS2. |
deviceId *Type: String | Device ID (push token). |
topicType: String | APNs topic (bundle identifier). Required for APNS2. |
environmentType: PNPushEnvironment | APNs environment. Accepted values: PNPushEnvironment.DEVELOPMENT, PNPushEnvironment.PRODUCTION. Required for APNS2. |
asyncType: Consumer<Result> | Consumer of a Result of type PNPushRemoveAllChannelsResult. |
Sample code
Remove all mobile push notifications
1
Returns
No payload is returned. Check result.isFailure() on error or handle exceptions via result.onFailure(...).