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
Asked
Active
Viewed 5,891 times
2
-
Yes it is. put html in `assets` folder and load using WebView – cYrixmorten Apr 14 '15 at 23:25
-
Should i put the html with all the folders ? cos my website includes other folders – Achraf Hamdi Apr 14 '15 at 23:26
-
Ask please... You want add website sites in your app and later check? You want use a website html file in your app in the navigation? – josedlujan Apr 14 '15 at 23:27
-
Have only done it using single html files but should work for folders with css etc as well .. is more or less just as loading your dev website using localhost. As long as the references are correct of course (refs to javascript,css..) – cYrixmorten Apr 14 '15 at 23:29
-
@josedlujan i have one page html with other folders (css...) and i want to use it in android without internet – Achraf Hamdi Apr 14 '15 at 23:32
-
@cYrixmorten can you give me some codes plz – Achraf Hamdi Apr 14 '15 at 23:34
2 Answers
1
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

josedlujan
- 5,357
- 2
- 27
- 49
-
Thats work for me, you sure with the path? i have 10 apps with this code. – josedlujan Apr 15 '15 at 17:35
-
Here 1: https://play.google.com/store/apps/details?id=com.manual.html.basico.desarolloweb.com – josedlujan Apr 15 '15 at 17:36
-
0
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");
-
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 – Achraf Hamdi Apr 15 '15 at 17:04