WebViewAssetLoader.PathHandler


public interface WebViewAssetLoader.PathHandler

Known direct subclasses
WebViewAssetLoader.AssetsPathHandler

Handler class to open a file from assets directory in the application APK.

WebViewAssetLoader.InternalStoragePathHandler

Handler class to open files from application internal storage.

WebViewAssetLoader.ResourcesPathHandler

Handler class to open a file from resources directory in the application APK.


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

Public methods

abstract @Nullable WebResourceResponse

Handles the requested URL by returning the appropriate response.

Public methods

handle

Added in 1.1.0
@WorkerThread
abstract @Nullable WebResourceResponse handle(@NonNull 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
@NonNull String path

the suffix path to be handled.

Returns
@Nullable WebResourceResponse

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