How to read cookies in a Phonegap-based Android app with Java

Just took me forever to get this straight, here is the trick on how to do it:

CookieSyncManager sym = CookieSyncManager.createInstance(appView.getContext());
CookieManager com = CookieManager.getInstance();
sym.sync();
String cookie = com.getCookie("file:///android_asset");

if (cookie == null) Log.d("MainActivity", "Cookie is null");
else{
	Log.d("MainActivity", "Cookie exists, value is:");
	Log.d("MainActivity", cookie);
}

Leave a Reply