Search code examples
androidandroid-studioandroid-webview

Android Kotlin using WebView with android_asset


I'm using Android Studio Dolphin 2021.3.1

I have a WebView setup as follows:

val wb = WebView(this)
wb.loadUrl("file:///android_assets/html/About.html")
setContentView(wb)

I have an asset folder setup as follows:

[asset folder structure][1]

in the project disk location:

MyApp/app/src/main/assets/html

but when the WebView is displayed i get

net::ERR_FILE_NOT_FOUND

Can somebody suggest how i can access the files like this? do i have the location on disk wrong? [1]: https://i.sstatic.net/c5Ury.png


Solution

  • Use url like this "file:///android_asset/html/About.html" with android_asset instead of android_assets