开发者

From where to load a saved HTML in a WebView?

开发者 https://www.devze.com 2023-02-24 14:27 出处:网络
I want that my WebView load my manipulated HTML which will be saved in /klw.html. Afterwards I load it with mWebView.loadUrl(\"file:///android_asset/klw.html\");

I want that my WebView load my manipulated HTML which will be saved in /klw.html. Afterwards I load it with mWebView.loadUrl("file:///android_asset/klw.html"); But when I try it in the emulator it says: "Webpage not available". Where is my fault? Do I have to load it from another directory?

Here is my code:

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");
    }
}


do you have the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> to make sure the file is being written?

do you have the <uses-permission android:name="android.permission.INTERNET"> to make sure that the URI being retrieved is not being retrieved as NULL then saving as a blank html?

0

精彩评论

暂无评论...
验证码 换一张
取 消