2

I am integrating html in android.I have created a web view, But i am not able load local html page. Surprisingly web view is loading 'http:google.com' properly, not my local html file. I have tried almost all possible link of SO. The error message is'Web Page could not be loaded'

WebView view  =  (WebView) findViewById(R.id.webView1);
    view.loadUrl("file:///assets/www/trialhtml.html");![enter image description here][1]

3 Answers 3

8

Create your HTML file and place it in the assets folder, then you need to add these lines to the onCreate method like this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView webView = new WebView(this);
    webView.loadUrl("file:///android_asset/test.html");
    setContentView(webView);
}

Here is the final result: App Screenshot

Sign up to request clarification or add additional context in comments.

2 Comments

How to open local html page in browser, can you help me with this also?? the error i m getting is android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///android_asset/www/trialhtml.html }
0

try below code :-

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String myURL = "file:///android_asset/index.html";
    WebView view  =  (WebView) findViewById(R.id.webView1);

    /*By default Javascript is turned off,
     * it can be enabled by this line.
     */
    view.getSettings().setJavaScriptEnabled(true);
    view.setWebViewClient(new WebViewClient());

    view.loadUrl(myURL);

}

Check ur file exist or not and also you can clean the project, and rebuild it.

Comments

0

paste your .html file in assets folder of your project folder. and create an xml file in layout folder with the fol code

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

add fol code in activity

setContentView(R.layout.my);
WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/www/trialhtml.html"); //new.html is html file na

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.