NowWebService class - Android

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:5分
  • The NowWebService class provides a function that launches a NowWebActivity that hosts a web view.

    表 : 1. Properties
    Name Type Description
    configuration NowServiceConfiguration class - Android Configuration information for the associated service, such as the ServiceNow instance URL and the name of the package.

    NowWebService - launch(context: Context, url: URL, nowWebTheme: NowWebTheme)

    Creates a NowWebActivity that hosts the web view.

    表 : 2. Parameters
    Name Type Description
    context Context Context to use for launching the associated activity.
    url URL URL of the web page to load. This web page must be on the target ServiceNow instance that the service was initialized with.
    nowWebTheme NowWebTheme Optional. NowWebTheme object to apply to the UI elements of the view controller.

    Default: Default theme

    表 : 3. Returns
    Type Description
    None

    The following code example shows how to call this function.

    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)
    }

    NowWebService – preloadWebCache(preloadUris: List<URI>)

    Preloads a list of specified java.net.URIs in a headless webview to pre-populate the webview cache with cacheable resources on the page.

    注:
    Completion of this function call is based on onPageFinished() being called in the webview, which does not take into account redirections or resources on the page. Because of this, preload may not be fully complete when this method returns.
    表 : 4. Parameters
    Name Type Description
    preloadUris List List of java.net.URIs to pre-load. All java.net.URIs must be relative or match the current host configured in the NowSDK.
    表 : 5. Returns
    Type Description
    None

    The following example shows how to use the webService.preloadWebCache() function to pre-load the mesp page.

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

    NowWebService – updateTheme(nowWebTheme: NowWebTheme)

    Updates the NowWeb UI theme with the specified UI theme. Use this function to update the web UI theme after it has been initially set using the launch() function, such as when changing the theme from light to dark.

    表 : 6. Parameters
    Name Type Description
    nowWebTheme NowWebTheme NowWebTheme object to apply to the UI elements of the view controller.
    表 : 7. Returns
    Type Description
    None

    The following code example shows how to update a light UI theme implemented using the launch() function to the dark UI theme using the updateTheme() function.

    val webService = getNowWebService()
    
    val lightTheme = object : NowWebTheme {
        override val brand: Int
            get() = Color.BLUE
    
        override val textPrimary: Int
            get() = Color.BLACK
    
        override val backgroundPrimary: Int
            get() = Color.WHITE
    
        // Override remaining theme colors
    }
    
    val darkTheme = object : NowWebTheme {
        override val brand: Int
            get() = Color.BLUE
    
        override val textPrimary: Int
            get() = Color.WHITE
    
        override val backgroundPrimary: Int
            get() = Color.BLACK
    
        // Override remaining theme colors
    }
    
    //launch NowWeb with light theme
    webService?.launch(activity, URL("https://instance-name.service-now.com"), lightTheme)
    
    //update NowWeb with dark theme
    webService?.updateTheme(darkTheme)