---
sourceDocument: Brazil API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/api-reference

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Setting up push notifications in your Android application

# Setting up push notifications in your Android application {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Setting up push notifications in your Android application

This guide explains how to configure push notifications for your Android application integrated with your ServiceNow® instance.
It details the key steps necessary to implement push functionality using ServiceNow's NowPushService and Firebase Cloud Messaging (FCM), enabling your app to receive and handle push notifications effectively.
Show full answer Show less  

## Key Implementation Steps

* **Create the NowPushService:** Initialize the NowPushService once during your app's lifecycle---typically in the Application class or a manager injected via dependency injection frameworks like Dagger/Hilt. Use `NowPushSDK.makePushService(instanceURL)` with your ServiceNow instance URL to obtain this service.
* **Register the push token:** Retrieve the device's unique push token from FirebaseMessaging and register it with NowPushService using `registerPushToken(pushToken, pushAppName)`. The `pushAppName` must match the name of your Android app registered in your ServiceNow instance.
* **Unregister the push token:** When the user logs out or exits the app, unregister the token using `unregisterPushToken(pushToken, pushAppName)` to stop receiving notifications.
* **Implement FirebaseMessagingService:** Override the `onMessageReceived(remoteMessage)` method to forward messages to NowPushService's `handlePush()` for processing. Currently, the service supports handling NowPushVirtualAgent notifications.
* **Handle new tokens:** Override `onNewToken(token: String)` to register updated push tokens with the NowPushService, ensuring continuous delivery of push notifications.

## Practical Benefits

Following these steps enables your Android application to securely and reliably receive push notifications from your ServiceNow instance. This integration supports enhanced user engagement through timely alerts, including virtual agent interactions, improving the overall user experience and responsiveness of your ServiceNow-powered mobile app.  
In addition to the tasks that you must perform on your ServiceNow®
instance to configure a push notification, you must also include specific code in your Android application.

## Create the NowSDK NowPushService {#mobsdk-and-setup-push-app__section_hyb_zxp_prb}

One of the first things that needs to be done in your application is to retrieve the NowSDK NowPushService. Add code similar to the following snippet early within your main code body.

    /**
     * Helper class used to handle different Now service instances.
     */
    @Singleton
    class SdkManager @Inject constructor() {

        private var nowPushService: NowPushService? = null

        /**
         * Create the NowPushService once in the lifetime of the application inside the Application
         * class or another manager class that will be injected into other classes via dagger/hilt.
         * NowPushService should be created after initializing the NowSDK
         */
        suspend fun getNowPushService(): NowPushService? {
            if (nowPushService != null) return nowPushService

            return NowPushSDK.makePushService(URL("https://instance-name.service-now.com")).getOrThrow()
                .also { this.nowPushService = it }
        }
    }

For additional information on the NowPushSDK.makePushService() method, refer to [NowPushSDK - makePushService(instanceURL: URL)](https://www.servicenow.com/docs/yT5W6iBxaPMZxcXc9V71bA#NPushSDK-makePushService_S_O_O "Creates a NowPush service.").

## Register the push token {#mobsdk-and-setup-push-app__section_kyr_4cq_prb}

Google
Firebase provides a unique push token that identifies the device and application to receive push notifications. In order for an application to receive push notification, you must register this token using the
NowPushService. Add a function similar to the following code snippet in your Android application. Ensure that you change PushAppName to the name of your Android application. This application must be registered with your ServiceNow® instance.

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

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

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

For additional information on the registerPushToken() method, refer to [NowPushService - registerPushToken(pushToken: String, pushApp: String, successCallback: Runnable, errorCallback: Consumer\<Throwable\>)](https://www.servicenow.com/docs/166NuTOtosLkf_up6WQlkw#NPushServ-registerPushToken_S_S_O_O "Registers a unique Firebase token with the ServiceNow instance used to identify the push notifications for the current Android device and specified application.").

## Unregister the push token

You need to unregister the push token whenever the user exits your application, such as
when the user logs out. Use code similar to the following code snippet to unregister the
push token. Ensure that you change PushAppName to the name of your Android application.

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

For additional information on the unregisterPushToken() method, refer to [NowPushService - unregisterPushToken(pushToken: String, pushApp: String, successCallback: Runnable, errorCallback: Consumer\<Throwable\>)](https://www.servicenow.com/docs/166NuTOtosLkf_up6WQlkw#NPushServ-unregPushToken_S_S_O_O "Unregisters the specified Firebase push token with the associated ServiceNow instance.").

## Implement the FirebaseMessagingService

You must implement the `FirebaseMessagingService` within your application.
To setup and implement this service, follow the instructions in the [Android Firebase documentation](https://firebase.google.com/docs/cloud-messaging/android/receive).

Once setup, override the onMessageReceived() method and pass the
RemoteMessage through to the `NowPushService`. If the
`NowPushService` recognizes the notification, it will process it and return
the notification object for the application to handle. Currently, the only implemented
notification is `NowPushVirtualAgent`. An unknown notification returns a
`NotSupportedPushError` object.

    //Custom coroutineScope created in the Firebase service class
    private val serviceCoroutineScope = CoroutineScope(Dispatchers.IO)

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
      serviceCoroutineScope.launch {
        val result = handleNowPush(remoteMessage)

        if (result.isSuccess) {
          when (val push = result.getOrNull()) {
            is NowPushVirtualAgent -> handleVirtualAgentPush(push)
          }
        } else {
          // Not a NowPush. Handle host app push notification message here
        }
      }
    }

    private suspend fun handleNowPush(remoteMessage: RemoteMessage): Result<NowPushPayload> {
      val nowPushService = sdkManager.getNowPushService()

      return suspendCoroutine { cont ->
        nowPushService?.handlePush(remoteMessage,
          { cont.resume(Result.success(it)) }, { cont.resumeWithException(it) })
      }
    }

For additional information on the handlePush() method, refer to [NowPushService - handlePush(remoteMessage: RemoteMessage, successCallback: Consumer\<NowPushPayload\>, errorCallback: Consumer\<Throwable\>)](https://www.servicenow.com/docs/166NuTOtosLkf_up6WQlkw#NPushServ-handlePush_S_O_O "Processes a push notification request.").

In addition, you must override onNewToken(token: String). Be sure to
pass the token through to the pushService.registerPushToken(), similar to
what was done in the "Register the push token" section.

