I'm trying to configure the Cookies to work with the WebView, but it doesn't work, when I configure the WebView to load the https://www.google.es , there appear the Cookies window, when I accept it and load again in the WebView (without leaving the app), it appears again.
I'm testing this code in a physical phone with Android 10 (LineageOS 17.1). I tried in a Xiaomi too, but in both doesn't work, always appear the Cookies window when I load the page.
I tried some tutorials and other StackOverflow post but none works, like configuring the CookieManager like this:
CookieManager.getInstance().setAcceptCookie(true);
or some other codes like this:
if (android.os.Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
Here is my code:
MainActivity.java
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
myWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.google.es");
AndroidManifest.xml
I have the <uses-permission android:name="android.permission.INTERNET" />
permission, should I need other one?
Use CookieSyncManager
to save it:
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
public void onPageFinished(WebView view, String url) {
CookieSyncManager.getInstance().sync();
}
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.