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 ?
CodePudding user response:
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 to app://
.
Then when I inspect the webview, it is loaded by default with file://
, so I do need to reload the webview and use the proper url https://com.myapp
, and finally I see my cookies.
I do not understand why the webview is inspecting over file://
though as I thought the app was automatically loaded over the custom scheme hostname