public interface

WebViewAssetLoader.PathHandler

 androidx.webkit.WebViewAssetLoader.PathHandler

Subclasses:

WebViewAssetLoader.AssetsPathHandler, WebViewAssetLoader.ResourcesPathHandler, WebViewAssetLoader.InternalStoragePathHandler

Overview

A handler that produces responses for a registered path.

Implement this interface to handle other use-cases according to your app's needs.

Methods of this handler will be invoked on a background thread and care must be taken to correctly synchronize access to any shared state.

On Android KitKat and above these methods may be called on more than one thread. This thread may be different than the thread on which the shouldInterceptRequest method was invoked. This means that on Android KitKat and above it is possible to block in this method without blocking other resources from loading. The number of threads used to parallelize loading is an internal implementation detail of the WebView and may change between updates which means that the amount of time spent blocking in this method should be kept to an absolute minimum.

Summary

Methods
public WebResourceResponsehandle(java.lang.String path)

Handles the requested URL by returning the appropriate response.

Methods

public WebResourceResponse handle(java.lang.String path)

Handles the requested URL by returning the appropriate response.

Returning a null value means that the handler decided not to handle this path. In this case, WebViewAssetLoader will try the next handler registered on this path or pass to WebView that will fall back to network to try to resolve the URL.

However, if the handler wants to save unnecessary processing either by another handler or by falling back to network, in cases like a file cannot be found, it may return a new WebResourceResponse(null, null, null) which is received as an HTTP response with status code 404 and no body.

Parameters:

path: the suffix path to be handled.

Returns:

for the requested path or null if it can't handle this path.