Android WebView code to load local HTML file
I have already discuss on CodeSpeedy how to build an android app which loads a website or web page within the android app using the inbuilt android WebView class. You already may know that you just have to put URL inside loadUrl() and you will be able to load that web page from your android app.
Now suppose you need to load a local HTML page or an offline HTML file within the WebView. So what you have to do? Now I am going to give you the process to load a local HTML file within your android app using the WebView class. It is really going to be very easy. Let’s go forward:
Use android WebView class to load local HTML file or offline HTML page
Here we go. Just remember the loadUrl() where I show you how to load this website:
It will load our website within android app. Now what to do for offline or local HTML file so that it will also load inside the android app. Well, to do it first you need to create a new android resource directory and name it assets inside app folder just like shown below:
All the other code will be remain same. To see the full code of main Java and layout file I referrer you to this post – Convert HTML Template Into Android App – Android Studio
That’s it! You have done. Now test your app and have fun.