title: How to programmatically accept all cookies in a WebView?
body: <p>My app uses a WebView and displays a dialog window titled &quot;Before you continue to Google&quot; that asks for permission to accept cookies. This window interferes with other dialogs set by the app, so I'd like to either accept cookies in advance and prevent the dialog from appearing or, failing that, detect when the permission dialog closes, so I can continue afterwards with the processing in the app.</p>
  <p>To prevent the Google dialog from displaying, I tried the following:</p>
  <pre><code>@Override
  public void onStart() {
      super.onStart();
  
      getSettings();
      WebAction();
  }
  
  public void WebAction(){
      browser_page.getSettings().setJavaScriptEnabled(true);
      browser_page.getSettings().setAppCacheEnabled(true);
      browser_page.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
      CookieManager.getInstance().setAcceptCookie(true);
      CookieManager.getInstance().setAcceptThirdPartyCookies(browser_page, true);
      browser_page.loadUrl(current_page);
      swipe.setRefreshing(true);
      browser_page.setWebViewClient(new WebViewClient() {
      .
      .
      .
  </code></pre>
  <p>I've read through all the SO posts relating to this and nothing has worked for me (min SDK for the app is 24, so post-Lollipop). Any help on this, or alternatively detecting when the permissions window is closed, would be really helpful.</p>