# WebViewAssetLoader.AssetsPathHandler

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/WebViewAssetLoader.java+class:androidx.webkit.WebViewAssetLoader.AssetsPathHandler) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

*** ** * ** ***


```
public final class WebViewAssetLoader.AssetsPathHandler implements WebViewAssetLoader.PathHandler
```

<br />

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.AssetsPathHandler#AssetsPathHandler(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/webkit/WebResourceResponse.html` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.AssetsPathHandler#handle(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html path)` Opens the requested file from the application's assets directory. |

## Public constructors

### AssetsPathHandler

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.1.0)

```
public AssetsPathHandler(@NonNull Context context)
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | `https://developer.android.com/reference/android/content/Context.html` 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 `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` object with a `null``https://developer.android.com/reference/java/io/InputStream.html` 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 `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` with `null``https://developer.android.com/reference/java/io/InputStream.html` 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 `https://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromName(java.lang.String)`. 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html path` | the suffix path to be handled. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/webkit/WebResourceResponse.html` | `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` for the requested file. |