Stay organized with collections
Save and categorize content based on your preferences.
ServiceWorkerController
abstract class ServiceWorkerController
Manages Service Workers used by WebView.
Example usage:
ServiceWorkerController swController = ServiceWorkerController.getInstance();
swController.setServiceWorkerClient(new ServiceWorkerClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
// Capture request here and generate response or allow pass-through
// by returning null.
return null;
}
});
Summary
Public methods |
open static ServiceWorkerController |
Returns the default ServiceWorkerController instance.
|
abstract ServiceWorkerWebSettings |
Gets the settings for all service workers.
|
abstract Unit |
Sets the client to capture service worker related callbacks.
|
Public constructors
ServiceWorkerController
ServiceWorkerController()
Deprecated: This class should not be constructed by applications, use getInstance()
instead to fetch the singleton instance.
Public methods
getInstance
open static fun getInstance(): ServiceWorkerController
Returns the default ServiceWorkerController instance. At present there is only one ServiceWorkerController instance for all WebView instances, however this restriction may be relaxed in the future.
getServiceWorkerWebSettings
abstract fun getServiceWorkerWebSettings(): ServiceWorkerWebSettings
Gets the settings for all service workers.
setServiceWorkerClient
abstract fun setServiceWorkerClient(client: ServiceWorkerClient?): Unit
Sets the client to capture service worker related callbacks. A ServiceWorkerClient
should be set before any service workers are active, e.g. a safe place is before any WebView instances are created or pages loaded.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ServiceWorkerController\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nServiceWorkerController\n=======================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/webkit/ServiceWorkerController \"View this page in Java\") \n\n```\nabstract class ServiceWorkerController\n```\n\n|---|---------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.webkit.ServiceWorkerController](#) |\n\nManages Service Workers used by WebView.\n\nExample usage: \n\n```kotlin\nServiceWorkerController swController = ServiceWorkerController.getInstance();\n swController.setServiceWorkerClient(new ServiceWorkerClient() {\n @Override\n public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {\n // Capture request here and generate response or allow pass-through\n // by returning null.\n return null;\n }\n });\n \n```\n\nSummary\n-------\n\n| Public constructors ||\n|------------------------------------------------------------------|---|\n| [ServiceWorkerController](#ServiceWorkerController())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open static [ServiceWorkerController](#) | [getInstance](#getInstance())`()` Returns the default ServiceWorkerController instance. |\n| abstract [ServiceWorkerWebSettings](/reference/kotlin/android/webkit/ServiceWorkerWebSettings) | [getServiceWorkerWebSettings](#getServiceWorkerWebSettings())`()` Gets the settings for all service workers. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setServiceWorkerClient](#setServiceWorkerClient(android.webkit.ServiceWorkerClient))`(`client:` `[ServiceWorkerClient](/reference/kotlin/android/webkit/ServiceWorkerClient)?`)` Sets the client to capture service worker related callbacks. |\n\nPublic constructors\n-------------------\n\n### ServiceWorkerController\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nServiceWorkerController()\n```\n\n**Deprecated:** *This class should not be constructed by applications, use [getInstance()](#getInstance()) instead to fetch the singleton instance.*\n\nPublic methods\n--------------\n\n### getInstance\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun getInstance(): ServiceWorkerController\n```\n\nReturns the default ServiceWorkerController instance. At present there is only one ServiceWorkerController instance for all WebView instances, however this restriction may be relaxed in the future.\n\n| Return ||\n|------------------------------|---------------------------------------------------------------------------|\n| [ServiceWorkerController](#) | the default ServiceWorkerController instance This value cannot be `null`. |\n\n### getServiceWorkerWebSettings\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun getServiceWorkerWebSettings(): ServiceWorkerWebSettings\n```\n\nGets the settings for all service workers.\n\n| Return ||\n|---------------------------------------------------------------------------------------|-------------------------------------------------------------------|\n| [ServiceWorkerWebSettings](/reference/kotlin/android/webkit/ServiceWorkerWebSettings) | the current ServiceWorkerWebSettings This value cannot be `null`. |\n\n### setServiceWorkerClient\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun setServiceWorkerClient(client: ServiceWorkerClient?): Unit\n```\n\nSets the client to capture service worker related callbacks. A [ServiceWorkerClient](/reference/kotlin/android/webkit/ServiceWorkerClient) should be set before any service workers are active, e.g. a safe place is before any WebView instances are created or pages loaded.\n\n| Parameters ||\n|----------|---------------------------------------------------------------------------------------------------------|\n| `client` | [ServiceWorkerClient](/reference/kotlin/android/webkit/ServiceWorkerClient)?: This value may be `null`. |"]]