- // Consume the event.
- return true;
- } else if (menuItemId == R.id.third_party_cookies) { // Third-party cookies.
- // Only act if the API >= 21. Otherwise, there are no third-party cookie controls.
- if (Build.VERSION.SDK_INT >= 21) {
- // Toggle the status of thirdPartyCookiesEnabled.
- cookieManager.setAcceptThirdPartyCookies(currentWebView, !cookieManager.acceptThirdPartyCookies(currentWebView));
-
- // Update the menu checkbox.
- menuItem.setChecked(cookieManager.acceptThirdPartyCookies(currentWebView));
-
- // Display a snackbar.
- if (cookieManager.acceptThirdPartyCookies(currentWebView)) {
- Snackbar.make(webViewPager, R.string.third_party_cookies_enabled, Snackbar.LENGTH_SHORT).show();
- } else {
- Snackbar.make(webViewPager, R.string.third_party_cookies_disabled, Snackbar.LENGTH_SHORT).show();
- }
-
- // Reload the current WebView.
- currentWebView.reload();
- }
-