public final class

WebViewAssetLoader.ResourcesPathHandler

extends java.lang.Object

implements WebViewAssetLoader.PathHandler

 java.lang.Object

↳androidx.webkit.WebViewAssetLoader.ResourcesPathHandler

Overview

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

Summary

Constructors
publicResourcesPathHandler(Context context)

Methods
public WebResourceResponsehandle(java.lang.String path)

Opens the requested file from application's resources directory.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ResourcesPathHandler(Context context)

Parameters:

context: used to resolve resources.

Methods

public WebResourceResponse handle(java.lang.String path)

Opens the requested file from application's resources 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 object with a null java.io.InputStream 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 with null java.io.InputStream 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 resource files are named using standard file extensions. If the file does not have a recognised extension, "text/plain" will be used by default.

Parameters:

path: the suffix path to be handled.

Returns:

for the requested file.