how open local html page in browser

前端 未结 5 1853
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 20:51

I am making an application in which i want to open a local html page in the browser. I am able to open google.com. But when i\'m opening local html file. But i am getting fo

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 21:33

    Open and load as raw resource and then place into WebView with loadData:

    InputStream page = getResources()
       .openRawResource(R.raw.my_web_page);
     BufferedReader r = new BufferedReader(new InputStreamReader(page));
    String s;
    while ((s = r.readLine()) != null)
      builder.append(s);
    r.close();
    myWebView.loadData(builder.toString(), "text/html", "UTF-8");
    

    Only your own application can easily read your assets.

    If you need to open the file with exactly the external browser, save the obtained string to some public location where the external browser could also access it.

提交回复
热议问题