简体   繁体   中英

Android WebView doesn't save games state

I had one problem with my app. WebView in my app doesn't save score results in some HTML5, Flash games (only in few of them). But Browsers and my IOS App it automatically do. I really don't what's the problem.

web=(WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
web.getSettings().setPluginState(WebSettings.PluginState.ON);
if (android.os.Build.VERSION.SDK_INT >= 21) {
      CookieManager.getInstance().setAcceptThirdPartyCookies(web, true);
 } 
else {
     CookieManager.getInstance().setAcceptCookie(true);
 }
 web.setWebViewClient(webViewClient);
 web.loadUrl(site);

I solved the problem:

       web=(WebView) findViewById(R.id.web);
        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setDomStorageEnabled(true);


        if (Build.VERSION.SDK_INT >= 19) {
            web.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }

        if (Build.VERSION.SDK_INT >= 21) {
            web.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptThirdPartyCookies(web, true);

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM