# WebViewAssetLoader.AssetsPathHandler

# 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)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.AssetsPathHandler "View this page in Java")


```
class WebViewAssetLoader.AssetsPathHandler : WebViewAssetLoader.PathHandler
```

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                      ### Public constructors                                                                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [AssetsPathHandler](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader.AssetsPathHandler#AssetsPathHandler(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`)` |

|                                           ### Public functions                                            |
|-----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html)`?` | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [handle](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader.AssetsPathHandler#handle(java.lang.String))`(path: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` 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)  

```
AssetsPathHandler(context: Context)
```  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | [Context](https://developer.android.com/reference/android/content/Context.html) used to resolve assets. |

## Public functions

### handle

```
@WorkerThread
fun handle(path: String): WebResourceResponse?
```

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](https://developer.android.com/reference/android/webkit/WebResourceResponse.html) object with a `null`[InputStream](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 [WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html) with `null`[InputStream](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 [guessContentTypeFromName](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                                         |
|-------------------------------------------------------------------------------------------|--------------------------------|
| `path: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the suffix path to be handled. |

|                                                  Returns                                                  |
|-----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| [WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html)`?` | [WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse.html) for the requested file. |