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

Achraf Hamdi
  • 75
  • 2
  • 10

2 Answers2

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
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");
Community
  • 1
  • 1
Kartik
  • 7,677
  • 4
  • 28
  • 50
  • 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