# WebViewAssetLoader.ResourcesPathHandler

# WebViewAssetLoader.ResourcesPathHandler

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.ResourcesPathHandler)  
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.ResourcesPathHandler "View this page in Java")

<br />

```
class WebViewAssetLoader.ResourcesPathHandler : WebViewAssetLoader.PathHandler
```

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                          ### Public constructors                                                                                                                           |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ResourcesPathHandler](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader.ResourcesPathHandler#ResourcesPathHandler(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.ResourcesPathHandler#handle(java.lang.String))`(path: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Opens the requested file from application's resources directory. |

## Public constructors

### ResourcesPathHandler

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

```
ResourcesPathHandler(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 resources. |

## Public functions

### handle

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

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[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 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: `[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. |