Loading html file from local folder into webview

I’m new to Android development.

I want to load a html file into a webview.

  • The count of session multiplies when I use Google Analytics Android SDK v4
  • Method onHandleIntent() does not get called
  • Android - Tabs, MapView, activities within tabs
  • Calculate compass bearing / heading to location in Android
  • Admob ad never displays in View
  • Android - How I can call javascript function and getting the retur value from javascript function
  • Note that there are so many relevant questions on SO like this, but they all deal with getting **.html* from assets folder.

    But I want to load html file from local folder, say “D://abc.html” because if my html is around 10Mb then corresponding apk size also goes upto 10mb.

    Any help appreciated.


    I tried webView.loadUrl("file:///D:/Projects/myWebsite/index.html");

    but it gives Web page not available and File not found error.

    Related posts:

    getting the highest GPS update rate from the GPS Hardware in my Android
    Dead loop in android webview backkey for redirect href link
    Android Speedometer (Needle Gauge)
    AppBarLayout.setExpanded(boolean, true) weird animation in support library 23.1.1
    How does TranslateAnimation works android?
    Share Image element transition display incorrect size
  • How do I make a tool bar (like a secondary action bar) in Android?
  • Android DatePicker display Month name
  • Android LinearLayout Gradient Background
  • Android: What does this warning message refer to? - (WebCore)
  • How to update contact number using Android
  • How to access res/drawable/“folder”
  • 3 Solutions collect form web for “Loading html file from local folder into webview”

    You can use:

       WebView webView = // ...

    In an Android application, files can be read from 3 types of locations:

    • Internal storage: Each app has its own, file names are relative to this location. URL takes form file:///myFolder/myFile.html

    • External storage: Needs permission and may not always be available. Get the root folder by calling Environment.getExternalStorageDirectory(). So, construct the URL using: String url = "file:///" + Environment.getExternalStorageDirectory().toString() + File.separator + "myFolder/myFile.html"

    • Assets: Stored in the apk. Read-only access. URL takes form file:///android_asset/myFolder/myFile.html (See also Loading an Android Resource into a WebView)

    In Android 4.4 KitKat, a “Not allowed to load local resource: file:///..” is thrown.
    arise when loadURL and the only alternative I’ve found is “loadDataWithBaseURL”.

                                 tmpDocumentText,"text/html", "UTF-8", null);

    WebView has loadData method http://developer.android.com/reference/android/webkit/WebView.html

    All you need to do is reading the file into String then feed it to WebView using loadData.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.