Make Android WebView not store cookies or passwords

前端 未结 6 1030
死守一世寂寞
死守一世寂寞 2020-11-30 22:13

I use an Android WebView for Twitter OAuth: Twitter asks the user to log in and authorize the application, I retrieve the access token and persist it in my application.

6条回答
  •  猫巷女王i
    2020-11-30 22:55

    You can use this to prevent cookies from being stored and clean cookies already stored:

    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookies(callback);
    cookieManager.setAcceptCookie(false);
    
    WebView webview = new WebView(this);
    WebSettings ws = webview.getSettings();
    ws.setSaveFormData(false);
    ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecated)
    

提交回复
热议问题