i want to add a website in my android app, i want an offline navigation without using a web servor. i mean when i click on the website it will open without internet. is it possible ? Thank you
2 Answers
Ok, then: First collocate the html, css, js or others files you need to charge in the same folder to do "easy way" but if you want you can use diferents path for each one.
To load the web:
urlcapitulo = "file:///android_asset/youweb.html"; //change for you html file
web = (WebView) findViewById(R.id.webkit); //using webview declare in xml
web.getSettings().setJavaScriptEnabled(true); // enable javascript
web.getSettings().setBuiltInZoomControls(true); // add zoom button
web.loadUrl(urlcapitulo); // load url
3 Comments
josedlujan
Thats work for me, you sure with the path? i have 10 apps with this code.
josedlujan
Here 1: play.google.com/store/apps/…
Achraf Hamdi
do i need a plugin or somthing ?
What have you tried till now? Post your code. Stackoverflow is not about making apps for you. Its about solving any issues you are facing. A simple google search gave me many results for your question.
Following is taken from here:
WebView wv = new WebView(this);
StringBuilder html = new StringBuilder();
html.append("<html>");
html.append("<head>");
html.append("<link rel=stylesheet href='css/style.css'>");
html.append("</head>");
html.append("<body>");
html.append("<h1>Some Heading</h1>");
html.append("<p>Some HTML content</p>");
html.append("<p><img style='width: 100%;' src='spidermen.jpg' /></p>");
html.append("</body></html>");
wv.loadDataWithBaseURL("file:///android_asset/", html.toString(), "text/html", "UTF-8", "");

See this as well.
For HTML file try this:
webView.loadUrl("file:///android_asset/filename.html");
1 Comment
Achraf Hamdi
i have seen this before and in my case i have 10 pages. i want a methode to import the page not write html code insite android classes thank you for your help
assetsfolder and load using WebView