美文网首页
android WebView各种坑

android WebView各种坑

作者: 笑笑_520 | 来源:发表于2019-01-02 11:04 被阅读0次

    1.WebView必不可少的一句

    webView.setWebViewClient(new WebViewClient());

    2.http和https混合支持

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 

        webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    }

    3.添加 Cookie

    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) CookieSyncManager.createInstance(context); 

     CookieManager cookieManager = CookieManager.getInstance(); 

    cookieManager.setAcceptCookie(true);

    cookieManager.setCookie(url, cookie);

    4.删除 Cookie

    CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    cookieManager.flush(); 

    }

    else{ 

    CookieSyncManager.createInstance(Application.getInstance()); 

    CookieSyncManager.getInstance().sync();

     }

    相关文章

      网友评论

          本文标题:android WebView各种坑

          本文链接:https://www.haomeiwen.com/subject/dyvalqtx.html