最近在做一款嵌入原生Android H5游戏.写完在Run app后发现报错,错误指向的是localStorage.setItem
WebView browser=(WebView)findViewById(R.id.Toweb);
/***打开本地缓存提供JS调用**/ browser.getSettings().setDomStorageEnabled(true); // Set cache size to 8 mb by default. should be more than enough browser.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(); browser.getSettings().setAppCachePath(appCachePath); browser.getSettings().setAllowFileAccess(true); browser.getSettings().setAppCacheEnabled(true);
//优先加载缓存页 browser.getSettings().setCacheMode( browser.getSettings().LOAD_CACHE_ELSE_NETWORK);
这样 H5页面就支持localStorage啦......