设置
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
mWebView.getSettings().setAppCachePath(appCachePath);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);
//mWebView.loadUrl("https://api.shanshanstory.com/local.html");
mWebView.loadUrl("http://h5.inner.evente.cn:8000/form");
写数据
@Override
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);
mProgress.setVisibility(View.GONE);
if (!isSetLocalStorage) {
writeData(webView);
webView.reload();
}
isSetLocalStorage = true;
}
public void writeData(WebView webView) {
//String key = "requestcout";
String key = "__EVENT__";
String val = base64Json;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript("window.localStorage.setItem('" + key + "','" + val + "');", null);
} else {
webView.loadUrl("javascript:localStorage.setItem('" + key + "','" + val + "');");
}
}