我想在webview中加載html字符串,即不是從URL或sdcard中的某個html文件加載。現在,html字符串有文本區域。用戶可以編輯它。現在我想將更改保存爲內部存儲器中的html文件。我該怎麼做。我檢查了其他SO問題,都使用相同的方法,即使用URL或使用一些JavaScript方法,這在我的情況下不起作用。我試過how to get html content from a webview?但它沒有幫助我。我認爲這實際上打開彈出窗口顯示代碼,甚至不允許用戶編輯哪些不是我的情況。從Webview獲取html字符串並將其存儲爲html文件
代碼(這裏的文本區域被TinyMCE的編輯器提供):
try {
InputStream input = getApplicationContext().getAssets().open("sample.html");
//Reader is = new BufferedReader(new InputStreamReader(input, "windows-1252"));
StringBuilder contentBuilder = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(input, "windows-1252"));
String str;
while ((str = in.readLine()) != null) {
contentBuilder.append(str);
}
in.close();
} catch (IOException e) {
}
content = contentBuilder.toString();
content=content.replace("This is some content that will be editable with TinyMCE.", html);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
view.getSettings().setPluginState(WebSettings.PluginState.ON);
view.addJavascriptInterface(new WebAppInterface(this), "Android");
view.addJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");
view.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:window.HtmlViewer.showHTML" +
"('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
});
view.loadDataWithBaseURL("file:///android_asset/", content, "text/html",
"UTF-8", null);
向我們展示您的代碼,請 – robjez
http://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a- webview?answertab = votes#tab-top – arun
@robjez添加了代碼。 –