android studio 打包webview後window.localStorage爲null的解決辦法

 

android studio 打包webview後window.localStorage爲null的解決辦法如下:

初始化的時候加入以下代碼即可解決。親測

 

        webView.loadUrl("http://192.168.1.169:8888/szrxApp/index.html");
        //模擬器專用地址
//        webView.loadUrl("http://10.0.2.2/szrxApp/index2.html");
        //以下代碼,加入可支持h5 localstore功能
        webView.getSettings().setDomStorageEnabled(true);

        webView.getSettings().setAppCacheMaxSize(1024*1024*8);

        String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();

        webView.getSettings().setAppCachePath(appCachePath);

        webView.getSettings().setAllowFileAccess(true);

        webView.getSettings().setAppCacheEnabled(true);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章