Android Studio 載入本地Assets中的html檔案
阿新 • • 發佈:2019-01-26
一共有2中方法:
1.
mWebView.loadUrl("file:///android_asset/index.html");
2,.
private void ProcessWebString() { // 載入 asset 檔案 String tpl = getFromAssets("index.html"); mWebView.loadDataWithBaseURL(null, tpl, "text/html", "utf-8", null); } /* * 獲取html檔案 */ public String getFromAssets(String fileName) { try { InputStreamReader inputReader = new InputStreamReader( getResources().getAssets().open(fileName)); BufferedReader bufReader = new BufferedReader(inputReader); String line = ""; String Result = ""; while ((line = bufReader.readLine()) != null) Result += line; return Result; } catch (Exception e) { e.printStackTrace(); } return ""; }