Cookie doesn't work properly in webview in android
I had similar issue and I added the below code and worked.
String myURL = "https://www.yourWebPage.com";
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.acceptCookie();
cookieManager.setAcceptFileSchemeCookies(true);
cookieManager.getInstance().setAcceptCookie(true);
cookieManager.getCookie(myURL);
Hope it helps.
WebView not accepting some cookies
If you want to pass your login users data to a cookie in Webview the do it like this
The other day I had to pass my login object to particular URL
as follow.
WebSettings settings = webViewRoi.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setAppCacheEnabled(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setAllowFileAccessFromFileURLs(true);
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
FormsDTO formsDTO = new FormsDTO();
FormsDTOProfile dtoProfile = new FormsDTOProfile(LoginActivity.loginInfoDTO.getProfile());
formsDTO.setProfile(dtoProfile);
formsDTO.setAuthorized(true);
formsDTO.setToken(LoginActivity.loginInfoDTO.getToken());
String out123 = gson.toJson(formsDTO);
String auth2 = URLEncoder.encode(out123, "UTF-8");
String z = "userInfo=" + auth2; // here userinfo is the key of cookie
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setCookie(url, z);
webViewRoi.setWebChromeClient(new WebChromeClient());
webViewRoi.loadUrl(url);
So if you know the key name of cookie then you can pass your login object through cookie. hope it helps you.
Android WebView doesn't store the cookies
Seems that there is a delay indeed with the cookies so I have to use this code:
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
CookieSyncManager.getInstance().sync();
Toast.makeText(getApplicationContext(), "Page loading complete", Toast.LENGTH_LONG).show();
}
});
Now it works fine.
Related Topics
How to Create Circular Progressbar in Android
Include .So Library in APK in Android Studio
Disabling the Fullscreen Editing View for Soft Keyboard Input in Landscape
Deleting a Gallery Image After Camera Intent Photo Taken
Using Intent in an Android Application to Show Another Activity
How to Use Jni Bitmap Operations for Helping to Avoid Oom When Using Large Images
Difference Between App:Srccompat and Android:Src in Android's Layout Xml
Android Read Text Raw Resource File
Android: Coloring Part of a String Using Textview.Settext()
Change Screen Orientation Programmatically Using a Button
Android - Set Max Length of Logcat Messages
How to Start Genymotion Device