Skip to content

Most visited

Recently visited

navigation

ServiceWorkerController

public abstract class ServiceWorkerController
extends Object

java.lang.Object
   ↳ android.webkit.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 constructors

ServiceWorkerController()

Public methods

static ServiceWorkerController getInstance()

Returns the default ServiceWorkerController instance.

abstract ServiceWorkerWebSettings getServiceWorkerWebSettings()

Gets the settings for all service workers.

abstract void setServiceWorkerClient(ServiceWorkerClient client)

Sets the client to capture service worker related callbacks.

Inherited methods

From class java.lang.Object

Public constructors

ServiceWorkerController

added in API level 24
ServiceWorkerController ()

Public methods

getInstance

added in API level 24
ServiceWorkerController getInstance ()

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.

Returns
ServiceWorkerController the default ServiceWorkerController instance

This value will never be null.

getServiceWorkerWebSettings

added in API level 24
ServiceWorkerWebSettings getServiceWorkerWebSettings ()

Gets the settings for all service workers.

Returns
ServiceWorkerWebSettings the current ServiceWorkerWebSettings

This value will never be null.

setServiceWorkerClient

added in API level 24
void setServiceWorkerClient (ServiceWorkerClient client)

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.

Parameters
client ServiceWorkerClient

This value may be null.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)