html - 内嵌app 的web 页面如何应用 app 内置的静态文件
黄舟
黄舟 2017-04-17 17:50:54
0
3
420

如题:
目前打算做一个内嵌在安卓 APP 里面的页面
打算把静态文件也放在 app 里面。
还要求能跟随版本更新~
求大神指导

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
大家讲道理

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);
大家讲道理

Just 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template