android webview cookie

使用CookieManager 管理cookie

        String url="yoururl";
        CookieManager manager=CookieManager.getInstance();
        String cookies=manager.getCookie(url);
        System.out.println("無cookies "+cookies);
        manager.setCookie(url,"hello");
        cookies=manager.getCookie(url);
        System.out.println("保存cookies "+cookies);
        manager.removeAllCookie();
        cookies=manager.getCookie(url);
        System.out.println("刪除cookies "+cookies);

輸出

       I/System.out: 無cookies null
       I/System.out: 保存cookies hello
       I/System.out: 刪除cookies null

思路:webview登錄頁驗證成功後,js調用android保存cookie,webview退出時,js調用android刪除cookie

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章