WebViewAssetLoader.AssetsPathHandler


public final class WebViewAssetLoader.AssetsPathHandler implements WebViewAssetLoader.PathHandler


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

Summary

Public constructors

Public methods

@Nullable WebResourceResponse

Opens the requested file from the application's assets directory.

Public constructors

AssetsPathHandler

Added in 1.1.0
public AssetsPathHandler(@NonNull Context context)
Parameters
@NonNull Context context

Context used to resolve assets.

Public methods

handle

@WorkerThread
public @Nullable WebResourceResponse handle(@NonNull String path)

Opens the requested file from the application's assets directory.

The matched prefix path used shouldn't be a prefix of a real web path. Thus, if the requested file cannot be found a WebResourceResponse object with a nullInputStream will be returned instead of null. This saves the time of falling back to network and trying to resolve a path that doesn't exist. A WebResourceResponse with nullInputStream will be received as an HTTP response with status code 404 and no body.

The MIME type for the file will be determined from the file's extension using guessContentTypeFromName. Developers should ensure that asset files are named using standard file extensions. If the file does not have a recognised extension, "text/plain" will be used by default.

Parameters
@NonNull String path

the suffix path to be handled.

Returns
@Nullable WebResourceResponse

WebResourceResponse for the requested file.