Mobile Push Notifications API for Android SDK

Unsupported docs

PubNub no longer maintains Android SDK docs, but our Java SDK or Kotlin SDK are fully compatible with the Android platform and you can use them to build mobile apps, ensuring stable software development.

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
Push type. One of: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2.
channels *
Type: List<String>
Channels to enable for push notifications.
deviceId *
Type: String
Device token used for push notifications.
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment. Required for APNS2.
async
Type: PNCallback<PNPushAddChannelResult>
Callback of type PNPushAddChannelResult.

Sample code

Add 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

No payload is returned. Check status.isError() on the status 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
Push type. One of: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2.
deviceId *
Type: String
Device token used for push notifications.
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment. Required for APNS2.
async
Type: PNCallback<PNPushListProvisionsResult>
Callback of type PNPushListProvisionsResult.

Sample code

List 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

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
Push type. One of: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2.
channels *
Type: List<String>
Channels to disable for push notifications.
deviceId *
Type: String
Device token used for push notifications.
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment. Required for APNS2.
async
Type: PNCallback<PNPushRemoveChannelResult>
Callback of type PNPushRemoveChannelResult.

Sample code

Remove 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

No payload is returned. Check status.isError() on the status object.

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
Push type. One of: PNPushType.FCM, PNPushType.GCM, PNPushType.APNS2.
deviceId *
Type: String
Device token used for push notifications.
topic
Type: String
APNs topic (bundle identifier). Required for APNS2.
environment
Type: PNPushEnvironment
APNs environment. Required for APNS2.
async
Type: PNCallback<PNPushRemoveAllChannelsResult>
Callback of type PNPushRemoveAllChannelsResult.

Sample code

Remove all mobile 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

No payload is returned. Check status.isError() on the status object.

Last updated on