2

Im trying to load terms and conditions of an app I am working on in my application. The client has provided me an html file of the terms and condition and I do not have any kind of server access. So technically the app needs to be carry that file with it. I have done web views where online data is shown in web view but I do not have any ice for this situation. I know I am missing a stupid point here. Please help

My layout file is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>
user3619542
  • 23
  • 1
  • 3

2 Answers2

3

Put your html file into your assets folder and load it with

WebView wv= (WebView)findViewById(R.id.webview);
wv.loadUrl("file:///android_asset/yourhtml.html");

Note. For 20126 Android Studio. For a new project, to create the "Assets Folder", right click on "app" in Projects, and drill down to "new Assets folder", then follow the wizard. Subsequently you can actually just drop the html (or other) files in to that folder in the OS; after a few moments AndroidStudio will recognize the files and show them in the Project panel.

Fattie
  • 27,874
  • 70
  • 431
  • 719
Emanuel
  • 8,027
  • 2
  • 37
  • 56
3

Any document to be used on the file is generally placed in the assets folder. Refer to this documentation. Here is a working snippet.

try {
            WebView mWebView = null;
            mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.loadUrl("file:///android_asset/index.html"); 
        } catch (Exception e) {
            // TODO: handle exception
            this.finish();
        }
Bijay Koirala
  • 525
  • 5
  • 9