如题:
目前打算做一个内嵌在安卓 APP 里面的页面
打算把静态文件也放在 app 里面。
还要求能跟随版本更新~
求大神指导
大家讲道理2017-04-17 17:52:54
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);
PHP中文网2017-04-17 17:52:54
WebView.load(url) supports local paths
and also supports loading files in the assets directory