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

This constructor is deprecated. This class should not be constructed by applications, use getInstance() instead to fetch the singleton instance.

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

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

ServiceWorkerController

Added in API level 24
public ServiceWorkerController ()

This constructor is deprecated.
This class should not be constructed by applications, use getInstance() instead to fetch the singleton instance.

Public methods

getInstance

Added in API level 24
public static 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 cannot be null.

getServiceWorkerWebSettings

Added in API level 24
public abstract ServiceWorkerWebSettings getServiceWorkerWebSettings ()

Gets the settings for all service workers.

Returns
ServiceWorkerWebSettings the current ServiceWorkerWebSettings This value cannot be null.

setServiceWorkerClient

Added in API level 24
public abstract 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.