Put the static file in the assets folder. If the file is an html file, it can be read using webview.loadUrl("file:///android_asset/demo.html")方式加载,如果是其他文件,可以通过InputStream in = context.getAssets().open("demo.js");. For example, a js file can be read and injected into the html page in the following way
InputStream in = context.getAssets().open("demo.js");
byte buff[] = new byte[1024];
ByteArrayOutputStream fromFile = new ByteArrayOutputStream();
do {
int numread = in.read(buff);
if (numread <= 0) {
break;
}
fromFile.write(buff, 0, numread);
} while (true);
jsString = fromFile.toString();
webview.loadUrl("javascript:"+jsString);
Put the static file in the assets folder. If the file is an html file, it can be read using
webview.loadUrl("file:///android_asset/demo.html")
方式加载,如果是其他文件,可以通过InputStream in = context.getAssets().open("demo.js");
. For example, a js file can be read and injected into the html page in the following wayJust put the files related to the web page into assets.
WebView.load(url) supports local paths
and also supports loading files in the assets directory