2

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

6
  • Yes it is. put html in assets folder and load using WebView Commented Apr 14, 2015 at 23:25
  • Should i put the html with all the folders ? cos my website includes other folders Commented Apr 14, 2015 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? Commented Apr 14, 2015 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..) Commented Apr 14, 2015 at 23:29
  • @josedlujan i have one page html with other folders (css...) and i want to use it in android without internet Commented Apr 14, 2015 at 23:32

2 Answers 2

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  
Sign up to request clarification or add additional context in comments.

3 Comments

Thats work for me, you sure with the path? i have 10 apps with this code.
do i need a plugin or somthing ?
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", "");

enter image description here

See this as well.

For HTML file try this:

webView.loadUrl("file:///android_asset/filename.html");

1 Comment

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.