I'm trying, from a Cordova plugin, to set a cookie to the webview. I've checked the cordova-android source and it appears that there is a CookieManager interface. When I'm trying to use it, the cookie isn't set when I inspect the webview.
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
ICordovaCookieManager cookieManager = webView.getCookieManager();
cookieManager.setCookiesEnabled(true);
cookieManager.setCookie("https://com.myapp", "test=test");
}
Note that I'm using the https://com.myapp as host as it is set in the hostname preference. I've also tried http://localhost and https://localhost..
How do I use ICordovaCookieManager to set a cookie ?
I will answer my own question since I've found the solution The code actually works! The issue is between scheme / hostname and inspecting.
The scheme actually does not set webView location, it always falls back onto
https://, even if you set it toapp://.Then when I inspect the webview, it is loaded by default with
file://because I hadAndroidInsecureFileModeEnabledset totrue, so I do need to reload the webview and use the proper urlhttps://com.myapp, and finally I see my cookies, or removeAndroidInsecureFileModeEnabled.