---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowPushService class - Android

# NowPushService class - Android {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read

The NowPushService class provides functions that enable interaction
with the Push Notification service.
{#NowPushServiceAndroidAPI__table_vx2_klw_5pb__entry__2}

| Name | Description |
|-|-|
| configuration | Service configuration to associate with the service. Data type: [NowServiceConfiguration](https://servicenow-prod.fluidtopics.net/Csuh2Bp1F37gr9cX8Z4xFg "The NowServiceConfiguration class enables you to configure the ServiceNow instance URL and package name for a feature service.") |
[Table 1. Properties]

{#NowPushServiceAndroidAPI__table_vx2_klw_5pb}

## NowPushService - handlePush(remoteMessage: RemoteMessage, successCallback:
Consumer\<NowPushPayload\>, errorCallback: Consumer\<Throwable\>) {#ariaid-title2}

Processes a push notification request.
Note:  
Currently the only implemented push notification type is `NowPushVirtualAgent`. Any other passed push notification type returns a [NotSupportedPushError](https://servicenow-prod.fluidtopics.net/jypHjGWK21hhaAoiBWOY_w#NotSupportedPushErrorAndroidAPI "A function from the NotSupportedPushError class is thrown when the NowPushSDK cannot process the push notification request. When this type of error is thrown, you must parse and handle the push notification outside of the MobileSDK framework.") object.
{#NPushServ-handlePush_S_O_O__table_aly_nvk_nrb__entry__3}

| Name | Type | Description |
|-|-|-|
| remote Message | [Remote Message](https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/RemoteMessage) | Notification as received by `com.google.firebase.messaging.FirebaseMessagingService.onMessageReceived`. For additional information, see [Receive messages in an Android app](https://firebase.google.com/docs/cloud-messaging/android/receive). |
| success Callback | [Consumer](https://developer.android.com/reference/kotlin/java/util/function/Consumer) \<[NowPushPayload](https://servicenow-prod.fluidtopics.net/fJf0s23_TJ8j6XnBcfo8Sw#NowPushPayloadAndroidInterface "The NowPushPayload interface defines the push notification payload that the NowSDK implements.")\> | Callback to return the processed NowPushPayload to. |
| error Callback | [Consumer](https://developer.android.com/reference/kotlin/java/util/function/Consumer) \<[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/)\> | Callback to return the thrown error to. If the error [NotSupportedPushError](https://servicenow-prod.fluidtopics.net/jypHjGWK21hhaAoiBWOY_w#NotSupportedPushErrorAndroidAPI "A function from the NotSupportedPushError class is thrown when the NowPushSDK cannot process the push notification request. When this type of error is thrown, you must parse and handle the push notification outside of the MobileSDK framework.") is thrown, the notification type is not supported by the mobile SDK, and must be processed outside of the mobile SDK framework. |
[Table 2. Parameters]

{#NPushServ-handlePush_S_O_O__table_aly_nvk_nrb} {#NPushServ-handlePush_S_O_O__table_bly_nvk_nrb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 3. Returns]

{#NPushServ-handlePush_S_O_O__table_bly_nvk_nrb}  
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](https://servicenow-prod.fluidtopics.net/jypHjGWK21hhaAoiBWOY_w#NotSupportedPushErrorAndroidAPI "A function from the NotSupportedPushError class is thrown when the NowPushSDK cannot process the push notification request. When this type of error is thrown, you must parse and handle the push notification outside of the MobileSDK framework.").

    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\>) {#ariaid-title3}

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.
{#NPushServ-registerPushToken_S_S_O_O__table_zhp_ccl_nrb__entry__3}

| Name | Type | Description |
|-|-|-|
| pushToken | String | Firebase token retrieved by either [com.google.firebase.messaging.FirebaseMessaging.getToken](https://firebase.google.com/docs/reference/js/v8/firebase.messaging.Messaging#gettoken) or [com.google.firebase.messaging.FirebaseMessagingService.onNewToken](https://firebase.google.com/docs/cloud-messaging/android/client). |
| pushApp | String | Name of the push application as specified in the Push Application table on the associated ServiceNow instance. |
| success Callback | [Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html) | Callback executed when the token registration is successful. |
| errorCallback | [Consumer](https://developer.android.com/reference/kotlin/java/util/function/Consumer) \<[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/)\> | Callback executed when the token registration fails. |
[Table 4. Parameters]

{#NPushServ-registerPushToken_S_S_O_O__table_zhp_ccl_nrb} {#NPushServ-registerPushToken_S_S_O_O__table_a3p_ccl_nrb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#NPushServ-registerPushToken_S_S_O_O__table_a3p_ccl_nrb}  
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\>) {#ariaid-title4}

Unregisters the specified Firebase push token with the associated
ServiceNow instance.
{#NPushServ-unregPushToken_S_S_O_O__table_ywx_bgl_nrb__entry__3}

| Name | Type | Description |
|-|-|-|
| pushToken | String | Firebase token to unregister. Retrieved by either [com.google.firebase.messaging.FirebaseMessaging.getToken](https://firebase.google.com/docs/reference/js/v8/firebase.messaging.Messaging#gettoken) or [com.google.firebase.messaging.FirebaseMessagingService.onNewToken](https://firebase.google.com/docs/cloud-messaging/android/client). |
| pushApp | String | Name 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 Callback | [Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html) | Callback executed when the token unregistration is successful. |
| erro rCallback | [Consumer](https://developer.android.com/reference/kotlin/java/util/function/Consumer) \<[Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/)\> | Callback executed when the token unregistration fails. |
[Table 6. Parameters]

{#NPushServ-unregPushToken_S_S_O_O__table_ywx_bgl_nrb} {#NPushServ-unregPushToken_S_S_O_O__table_zwx_bgl_nrb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 7. Returns]

{#NPushServ-unregPushToken_S_S_O_O__table_zwx_bgl_nrb}  
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)
    })


