我希望我WebView
加载我操纵的 HTML,它将保存在 /klw.html 中。之后我加载它mWebView.loadUrl("file:///android_asset/klw.html");
但是当我在模拟器中尝试它时它说:“网页不可用”。我的错在哪里?我必须从另一个目录加载它吗?
这是我的代码:
public class Stundenplan extends Activity {
String url = "http://info.tam.ch/display/timetable_external.php?school=klw&sem=54&class=26&week=16";
Document document;
public void main(String... args){
try {
document = Jsoup.connect(url).get();
}
catch (IOException e) {
e.printStackTrace();
}
Element head = document.head();
head.append("<link rel=\"stylesheet\" href=\"klw.css\">");
String html = document.html();
String charset = Jsoup.connect(url).response().charset();
// ...
try {
Writer writer = new PrintWriter("/klw.html", charset);
writer.write(html);
writer.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
main();
WebView mWebView;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setWebViewClient(new WebViewClient());
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.loadUrl("file:///android_asset/klw.html");
}
}