Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowPushService class- Android

The NowPushService class provides functions that enable interaction with the Push Notification service.

NameDescription
configurationService configuration to associate with the service.Data type: NowServiceConfiguration

Parent Topic:Mobile SDK - Android

NowPushService - handlePush(remoteMessage: RemoteMessage, successCallback: Consumer<NowPushPayload>, errorCallback: Consumer<Throwable>)

Processes a push notification request.

Note: Currently the only implemented push notification type is NowPushVirtualAgent. Any other passed push notification type returns a NotSupportedPushError object.

NameTypeDescription
remote MessageRemote MessageNotification as received by com.google.firebase.messaging.FirebaseMessagingService.onMessageReceived. For additional information, see Receive messages in an Android app.
success CallbackConsumer <NowPushPayload>Callback to return the processed NowPushPayload to.
error CallbackConsumer <Throwable>Callback to return the thrown error to. If the error NotSupportedPushError is thrown, the notification type is not supported by the mobile SDK, and must be processed outside of the mobile SDK framework.
TypeDescription
None 

This example shows how to override onMessageReceived() and pass the RemoteMessage through to the NowPushService. If the NowPushService recognizes the notification type, it processes the request and returns the notification object for the application to handle. Otherwise it throws the NotSupportedPushError.

override fun onMessageReceived(remodeeMessage: RemoteMessage){
  pushService.handlePush(remoteMessage, { push ->
    when (push) {
      is NowPushVirtualAgent → handleVirtualAgentPush(push)
    }, { error ->
        Log.e(TAG, "Unknown push", error)
        handleAppPushNotification(remoteMessage)
    })
}

NowPushService - registerPushToken(pushToken: String, pushApp: String, successCallback: Runnable, errorCallback: Consumer<Throwable>)

Registers a unique Firebase token with the ServiceNow instance used to identify the push notifications for the current Android device and specified application.

In order for the ServiceNow instance to generate notifications Android device to receive notifications from the application, this token must be registered.

NameTypeDescription
pushTokenStringFirebase token retrieved by either com.google.firebase.messaging.FirebaseMessaging.getToken or com.google.firebase.messaging.FirebaseMessagingService.onNewToken.
pushAppStringName of the push application as specified in the Push Application table on the associated ServiceNow instance.
success CallbackRunnableCallback executed when the token registration is successful.
errorCallbackConsumer <Throwable>Callback executed when the token registration fails.
TypeDescription
None 

This example registers a push token for the current Android device and the application "PushAppName".

FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
  val token = task.result

  if (!task.isSuccessful || token == null) {
    throw Exception("Unable to fetch token"))
  }

  pushService.registerPushToken(token, "PushAppName", {
    Log.v(TAG, "Successfully registered push token")
  }, { e ->
    Log.e(TAG, "Error registering push", e)
  })
}

NowPushService - unregisterPushToken(pushToken: String, pushApp: String, successCallback: Runnable, errorCallback: Consumer<Throwable>)

Unregisters the specified Firebase push token with the associated ServiceNow instance.

NameTypeDescription
pushTokenStringFirebase token to unregister. Retrieved by either com.google.firebase.messaging.FirebaseMessaging.getToken or com.google.firebase.messaging.FirebaseMessagingService.onNewToken.
pushAppStringName of the push application associated with the token to unregister. This information is stored in the Push Application table on the associated ServiceNow instance.
success CallbackRunnableCallback executed when the token unregistration is successful.
erro rCallbackConsumer <Throwable>Callback executed when the token unregistration fails.
TypeDescription
None 

This code example shows how to unregister a push token such as when the user logs out of the application.

pushService.unregisterPushtoken(token, "PushAppName", {
  Log.v(TAG, "Successfully unregistered push token")
},  { e ->
  Log.e(TAG, "Error unregistering push", e)
})