search

Home  >  Q&A  >  body text

html - 内嵌app 的web 页面如何应用 app 内置的静态文件

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

黄舟黄舟2773 days ago427

reply all(3)I'll reply

  • 大家讲道理

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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:52:54

    Just put the files related to the web page into assets.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:52:54

    WebView.load(url) supports local paths
    and also supports loading files in the assets directory

    reply
    0
  • Cancelreply