I'm failing at the moment in letting my app delete the browser cookies or some specific cookies.
The way I found was to implement the following:
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
But nothing is happening. An with the method hasCookie() is get false as return. Is there no way for deleting a cookie from inside my app?
Thanks for your help!
You can use CookieSyncManager to delete cookies from your own WebView widget(s).
You cannot delete cookies from third-party applications that use WebView or other Web rendering engines.
Related
I'm currently developing a cordova app with an ADFS authentication through inappbrowser.
This works well so far. But I need to retrieve the session cookie stored in the webview instance and be able to use it in another application with the same mechanism, so the user doesn't need to log in twice, as both apps use the same corporate login.
I've tried recovering the cookie with CookieManager
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(url);
However, it doesn't list the session cookie. It seems CookieManager doesn't return those cookies without expiration date.
I've been able to successfully terminate the session by running
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeSessionCookies(null);
So I'm sure the session cookie is there, but I'm unable to get/manipulate it.
I'm using Java code on an Android app to login and I receive cookies after I successfully login (using Retrofit).
What I want to do is if the login is successful and I go to a different tab which has a WebView that I'm automatically logged in with my browser cookie. On iOS this works perfectly. On Android I think I have to change something in my code so I'm using the following code to set the cookies in my CookieManager:
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
for(String cookie: response.headers().values("Set-Cookie")){
System.out.println("cookie = " + cookie);
cookieManager.setCookie(Constants.baseURL, cookie);
}
This works fine and if I reload the WebView it seems to have all the right cookies, why am I not logged in in the WebView and does this work in iOS? Do I need to add something else?
May be you have forgotten to use CookieSyncManager.createInstance(..)
And call sync on obtained instance
I have my app ("myapp") with following example package signature: com.example.mycorp.myapp
I browsed via adb shell the app folder /data/data/com.example.mycorp.myapp/ to find any cookies - in vain.
Since I have WebView objects showing external links (html) and Google Login as an example, there should be some cookies created (at least iOS colleagues have there cookies on the same app for iOS).
So where are can I find any cookies regarding my own app?
Programmatically by means of CookieManager:
Memeber variable
private CookieManager cookieManager = null;
In a onCreate() or another constructor
cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
A checkCookies() Method which can be triggered frequently
List<HttpCokie> cookies = cookieManager.getCookieStore().getCookies();
Now, iterate through cookies and print them out.
If you want to get the cookie value you can use this:
CookieManager.getInstance().getCookie("http://the.url.com")
More help will be provided here:
http://developer.android.com/reference/android/webkit/CookieManager.html#getCookie(java.lang.String)
I'm writing a Cordova app and I would like to access its HTTP secure cookie from a plugin. I want to encrypt / disable it until the user enters a valid pin.
All help is greatly appreciated. Thank you.
The way I would do it would be to enable/disable the cookies for the entire application:
CookieManager mCookieManager = CookieManager.getInstance();
CookieSyncManager.createInstance(this);
mCookieManager.setAcceptCookie(false); //disables cookies for the WebView until the user enters a correct pin
if(getUsersPin()) { //getUsersPin() gets the pin from the user
mCookieManager.setAcceptCookie(true);
}
There have been a couple of question's about syncing cookies, but none of the solutions described, seem to work for me.
I've got one webView in my Android app. The first time I show it, I use a HTTP POST to log the user in, and the server shows the homepage. Als long as I stay in this webview, the session is retained. But as soon as I do a new loadUrl on the webview, apparanetly the session is lost, and the server wants me to log in again.
I've tried android-share-session-between-webview-and-httpclient. It doesn't seem to work, in my onPageStarted the list of cookies is always empty.
I've also tried to start syncing cookies before the initial loadURL (with POST) of the webView:
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
CookieSyncManager.createInstance(getBaseContext());
CookieSyncManager.getInstance().startSync();
and then in onPageFinished:
CookieSyncManager.getInstance().sync();
This doesn't work either, so now I really don't know what to do. Does anyone have experience with this and can explain to me how to do it?