Android webview如何打开本地存储,提供给JS调用html5的lwindow.localStorage功能

来源:互联网 发布:广州 java 三年 编辑:程序博客网 时间:2024/06/17 05:18
mWebView = (WebView) this.findViewById(R.id.webview);WebSettings settings = mWebView.getSettings();settings.setJavaScriptEnabled(true);//settings.setPluginsEnabled(true);/***打开本地缓存提供JS调用**/mWebView.getSettings().setDomStorageEnabled(true);    // Set cache size to 8 mb by default. should be more than enoughmWebView.getSettings().setAppCacheMaxSize(1024*1024*8);    // This next one is crazy. It's the DEFAULT location for your app's cache    // But it didn't work for me without this line.    // UPDATE: no hardcoded path. Thanks to Kevin Hawkins    String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();    mWebView.getSettings().setAppCachePath(appCachePath);    mWebView.getSettings().setAllowFileAccess(true);    mWebView.getSettings().setAppCacheEnabled(true);


java的navtive代码只要设置了以上参数,就可以为JS端提供本地存储了,记住这个参数需要API>=7使用,也就是android2.1版本以上才可以。

原创粉丝点击