Upload local html file in android webview

I am trying to upload the contents of an html file to a webview in android. However, this gives me a "Webpage Error". If I try to use websites like google or yahoo, they work.

The html file is located under src> main> assests> index.html

Can someone help me with this problem. Thanks.

Below is my code:

setContentView(R.layout.activity_main); WebView mWebView; mWebView = (WebView) findViewById(R.id.activity_main_webview); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.loadUrl("file:///android_asset/index.html"); 

XML file:

 <WebView android:id="@+id/activity_main_webview" android:layout_width="match_parent" android:layout_height="match_parent" /> 
+7
android html android-studio webview local
source share
1 answer

The html file should be placed in the assets folder (pay attention to the spelling), which will belong to the root directory of your project.

So move

 src/main/assests/index.html 

to

 assets/index.html 

In an Android Studio project, use this folder:

 /app/src/main/assets/index.html 
+8
source share

All Articles