Push Notifications API for PubNub Android SDK

PubNub's Mobile Push Gateway 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 Gateway, 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 Push Notifications.

Adding 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.

Description

Enable push notifications on provided set of channels.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the Android V4 SDK:

pubnub.addPushNotificationsOnChannels().pushType(PNPushType).channels(List<String>).deviceId(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2
channelsList<String>YesAdd push notifications on the specified channels.
deviceIdStringYesThe device ID (token) to associate with 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).
asyncPNCallback<PNPushAddChannelResult>OptionalPNCallback of type PNPushAddChannelResult.

Basic Usage

Adding Device to Channel

// for FCM/GCM
pubnub.addPushNotificationsOnChannels()
.pushType(PNPushType.FCM)
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.deviceId("googleDevice")
.async(new PNCallback<PNPushAddChannelResult>() {
@Override
public void onResponse(PNPushAddChannelResult result, PNStatus status) {
// handle response.
}
});

// for APNS2
pubnub.addPushNotificationsOnChannels()
.pushType(PNPushType.APNS2)
show all 23 lines

Returns

The addPushNotificationsOnChannels() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().

Listing 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.

Description

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 Android V4 SDK:

pubnub.auditPushChannelProvisions().pushType(PNPushType).deviceId(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2
deviceIdStringYesThe device ID (token) to associate with 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).
asyncPNCallback<PNPushListProvisionsResult>OptionalPNCallback of type PNPushListProvisionsResult.

Basic Usage

Listing Channels For Device

// for FCM/GCM
pubnub.auditPushChannelProvisions()
.deviceId("googleDevice")
.pushType(PNPushType.FCM)
.async(new PNCallback<PNPushListProvisionsResult>() {
@Override
public void onResponse(PNPushListProvisionsResult result, PNStatus status) {

}
});

// for APNS2
pubnub.auditPushChannelProvisions()
.deviceId("appleDevice")
.pushType(PNPushType.APNS2)
show all 23 lines

Returns

The auditPushChannelProvisions() operation returns a PNPushListProvisionsResult which contains the following operations:

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

Removing 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.

Description

Disable push notifications on provided set of channels.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the Android V4 SDK:

pubnub.removePushNotificationsFromChannels().pushType(PNPushType).deviceId(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2
channelsList<String>YesAdd push notifications on the specified channels.
deviceIdStringYesThe device ID (token) to associate with 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).
asyncPNCallback<PNPushRemoveChannelResult>OptionalPNCallback of type PNPushRemoveChannelResult.

Basic Usage

Removing Device From Channel

// for FCM/GCM
pubnub.removePushNotificationsFromChannels()
.deviceId("googleDevice")
.channels(Arrays.asList("ch1", "ch2", "ch3"))
.pushType(PNPushType.FCM)
.async(new PNCallback<PNPushRemoveChannelResult>() {
@Override
public void onResponse(PNPushRemoveChannelResult result, PNStatus status) {

}
});

// for APNS2
pubnub.removePushNotificationsFromChannels()
.deviceId("appleDevice")
show all 25 lines

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 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.

Description

Disable push notifications from all channels registered with the specified pushToken.

Method(s)

To run Remove all push notifications you can use the following method(s) in the Android V4 SDK:

pubnub.removeAllPushNotificationsFromDeviceWithPushToken().pushType(PNPushType).deviceId(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDescription
pushTypePNPushTypeYesAccepted values: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2
deviceIdStringYesThe device ID (token) to associate with 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).
asyncPNCallback<PNPushRemoveAllChannelsResult>OptionalPNCallback of type PNPushRemoveAllChannelsResult.

Basic Usage

Remove all push notifications

// for FCM/GCM
pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
.deviceId("googleDevice")
.pushType(PNPushType.FCM)
.async(new PNCallback<PNPushRemoveAllChannelsResult>() {
@Override
public void onResponse(PNPushRemoveAllChannelsResult result, PNStatus status) {

}
});

// for APNS2
pubnub.removeAllPushNotificationsFromDeviceWithPushToken()
.deviceId("appleDevice")
.pushType(PNPushType.APNS2)
show all 23 lines

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