{"id":639,"date":"2018-07-08T13:24:30","date_gmt":"2018-07-08T05:24:30","guid":{"rendered":"https:\/\/www.dd-home.top:1443\/?p=639"},"modified":"2018-07-08T13:24:30","modified_gmt":"2018-07-08T05:24:30","slug":"android-webview-%e8%ae%be%e7%bd%aecookie%e5%92%8c%e6%b8%85%e9%99%a4cookie","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=639","title":{"rendered":"android WebView \u8bbe\u7f6ecookie\u548c\u6e05\u9664Cookie"},"content":{"rendered":"<p><!--more--><\/p>\n<pre class=\"lang:java decode:true \" title=\"\u8bbe\u7f6eCookie\">   public static boolean syncCookie(String url, String cookie, Context context) {\n        if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP) {\n            CookieSyncManager.createInstance(context);\n        }\n        CookieManager cookieManager = CookieManager.getInstance();\n        cookieManager.setCookie(url, cookie);\/\/\u5982\u679c\u6ca1\u6709\u7279\u6b8a\u9700\u6c42\uff0c\u8fd9\u91cc\u53ea\u9700\u8981\u5c06session id\u4ee5\"key=value\"\u5f62\u5f0f\u4f5c\u4e3acookie\u5373\u53ef\n        String newCookie = cookieManager.getCookie(url);\n        return TextUtils.isEmpty(newCookie) ? false : true;\n    }<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"lang:java decode:true \" title=\"\u6e05\u9664Cookie\"> public static void clearCookies(Context context) {\n\n        if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP_MR1) {\n            Log.i(TAG, \"Using clearCookies code for API &gt;=\" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));\n            CookieManager.getInstance().removeAllCookies(null);\n            CookieManager.getInstance().flush();\n        } else {\n            Log.d(TAG, \"Using clearCookies code for API &lt;\" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));\n            CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);\n            cookieSyncMngr.startSync();\n            CookieManager cookieManager = CookieManager.getInstance();\n            cookieManager.removeAllCookie();\n            cookieManager.removeSessionCookie();\n            cookieSyncMngr.stopSync();\n            cookieSyncMngr.sync();\n        }\n    }<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[43],"class_list":["post-639","post","type-post","status-publish","format-standard","hentry","category-android","tag-cookie"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=639"}],"version-history":[{"count":0,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/639\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}