Display web pages hosted on your ServiceNow instance

  • Release version: Yokohama
  • Updated January 30, 2025
  • 2 minutes to read
  • Summarize
    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 Display web pages hosted on your ServiceNow instance

    This feature enables ServiceNow customers to display web pages hosted on their ServiceNow instance directly within a native Android application. The Mobile SDK manages authentication and session handling seamlessly, while the NowWebSDK API facilitates interaction with web pages on the ServiceNow platform, preserving their dynamic capabilities.

    Show full answer Show less

    Key Features

    • NowWebService Creation: Instantiate a NowWebService object by calling makeWebService() with your ServiceNow instance URL and an initialized NowSDK. Maintaining a reference to this service during usage is recommended.
    • Pre-loading Pages: Improve initial load times by pre-loading cacheable pages in the background using preloadWebCache(), which accepts a list of URIs to preload.
    • Displaying Web Content: Use the NowWebService instance to launch an activity that displays ServiceNow-hosted web pages within your Android app. The launch method requires the URL of the page hosted on your instance.
    • Customizable UI Themes: Apply custom color themes to all UI elements within the web view by implementing the NowWebTheme interface and passing it to the launch method. This allows branding and theming consistency within your application.

    Practical Use and Benefits

    By integrating these capabilities, ServiceNow customers can embed fully interactive ServiceNow web pages into their Android apps, providing users with seamless and secure access to instance-hosted content without leaving the app. Pre-loading improves user experience by reducing wait times, and customizable themes ensure the embedded content aligns with corporate branding.

    You can display web pages hosted within your ServiceNow instance in your native Android application.

    The Mobile SDK provides seamless handling of the required authentication and session management, while the NowWebSDK API provides the functionality required to handle pages residing on your ServiceNow instance. These web pages have all the dynamic interactions that are possible on the ServiceNow platform.

    To use these features, you must first create an instance of the NowWebService. To do this, you must call the makeWebService() method and provide the URL to your ServiceNow instance and an already initialized NowSDK. In addition, you must have imported NowWeb within your application. You should hold a reference to the NowWebService for as long as you're using the NowWeb service.

    The following shows an example of how to create a NowWebService object:

    /**
     * Helper class used to handle different Now service instances.
     */
    @Singleton
    class SdkManager @Inject constructor() {
    
        private var nowWebService: NowWebService? = null
    
        /**
         * Create the NowWebService 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.
         * NowWebService should be created after initializing the NowSDK
         */
        suspend fun getNowWebService(): NowWebService? {
            if (nowWebService != null) return nowWebService
    
            return NowWebSDK.makeWebService(URL("https://instance-name.service-now.com")).getOrThrow()
                .also { this.nowWebService = it }
        }
    }

    Pre-load pages to improve NowWeb load time

    You can pre-load pages with cacheable resources in the background to improve initial NowWeb load times. The following example shows how to use the webService.preloadWebCache() function to pre-load the mesp page. This method takes a list of URIs to pre-fetch more pages.

    suspend fun preloadNowWeb() {
      val webService = sdkmanager.getNowWebService()
      webService.preloadWebCache(listOf(URI("mesp")))
    }

    Create views to display web content

    After you've instantiated an instance of NowWebService, you can use it to launch an activity to display web pages hosted on your ServiceNow instance.

    The following example shows how to launch a NowWeb activity:

    //Activity that will start the NowWeb
    class MainActivity : AppCompatActivity() {
    
      @Inject
      lateinit var sdkManager: SdkManager
    
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        // Start NowWeb
        lifecycleScope.launch {
          sdkManager.getNowWebService()?.launch(this@MainActivity, URL("https://instance-name.service-now.com"), object : NowWebTheme{})
        }
      }
    }

    In this example, url is the URL of the initial page to load within the view. This URL must point to a page that is hosted on the specified ServiceNow instance.

    Color theme support for NowWeb UI elements

    You can specify a custom color theme that applies to all UI elements within a view when calling the NowWebService launch() method. To create this custom color theme, create a type that implements the NowWebTheme interface and pass it in the theme parameter of the NowWebService.launch() call.

    suspend fun launchNowWeb() {
        val webService = getNowWebService()
    
        val webTheme = object : NowWebTheme {
            override val brand: Int
                get() = Color.BLUE
    
            override val textPrimary: Int
                get() = Color.BLACK
    
            //Override remaining theme colors
        }
        webService?.launch(activity, URL("https://instance-name.service-now.com"), webTheme)
    }

    For additional information on applying color themes within a web view, see Use NowUIColoring to theme NowWebTheme and NowChatTheme.