{"id":153,"date":"2022-05-29T06:51:04","date_gmt":"2022-05-28T22:51:04","guid":{"rendered":"https:\/\/www.nickyoo7.com\/?p=153"},"modified":"2022-05-29T06:51:04","modified_gmt":"2022-05-28T22:51:04","slug":"android-webview-injection-cookie","status":"publish","type":"post","link":"https:\/\/www.nickyoo7.com\/?p=153","title":{"rendered":"Android WebView  injection Cookie"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">    \/**\r\n     * injection Cookie\r\n     *\r\n     * @param url  WebView \u958b\u555f\u7684\u9023\u7d50\r\n     *\/\r\n    void injectionCookie(String url) {\r\n        try {\r\n            String StringCookie;\r\n            if ( ) {\/\/\r\n                StringCookie = \"\";\r\n            } else { \/\/\r\n                 StringCookie = \"key=\" + value + \";path=\/\";\r\n            }\r\n            CookieManager cookieManager = CookieManager.getInstance();\r\n            if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {\r\n                cookieManager.removeSessionCookies(null);\r\n                cookieManager.flush();\r\n            } else {\r\n                cookieManager.removeSessionCookie();\r\n                CookieSyncManager.getInstance().sync();\r\n            }\r\n            cookieManager.setAcceptCookie(true);\r\n            cookieManager.setCookie(url, StringCookie);\r\n        } catch (Exception e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n\u8a3b\uff1a\u4ee5\u4e0a\u9700webview \u8a2d\u5b9a\u5c6c\u6027\u3001loadUrl\u4e4b\u524d\u4f7f\u7528<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * injection Cookie * * @param url WebView \u958b\u555f\u7684\u9023\u7d50 *\/  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.nickyoo7.com\/?p=153\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Android WebView  injection Cookie\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-android","entry"],"_links":{"self":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":1,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nickyoo7.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}