androidkotlinwebviewandroid-internal-storage

Kotlin load html from internal storage to webview


i would like to load an html page from my internal storage into a webview but i couldn't find any exemple on how to do it. Here is what i can do :

webView.loadUrl("file:///android_asset/article_0028_0071.html")

This work but i had to manually add the page to asset. Then i got the same file in internal storage the full path is : /data/user/0/com.example.app/files/articles/article_0028_0071.html So i have tried :

path = "/data/user/0/com.example.app/files/articles/article_0028_0071.html"
webView.loadUrl(path)

This give me no error but a blanc page. also tried with "file:///articles/article_0028_0071.html" but same result no error blanc page.

So i would like to know how should i write the path to access html from internal storage?


Solution

  • You just need to add file:/// before your path.

    path = "file:///data/user/0/com.example.app/files/articles/article_0028_0071.html"
    webView.loadUrl(path)
    

    This work perfectly