Adding CookieManager to android Childbrowser

白昼怎懂夜的黑 提交于 2019-12-11 09:36:09

问题


I am trying to get local cookies (file://) to work on android 3.1+ within ChildBrowser. I found a blog response talking about this specific issue and how to remedy it with Cookie Manager. I can't figure out where in the plugin to put the code. Has anyone successfully implemented this?


Comment Below from http://code.google.com/p/android/issues/detail?id=3739

Comment 16 by edtechk...@gmail.com, Feb 1, 2012 I got this thing working, for Android 2.2, javascript's document.cookie works fine, just make sure that in your Webview...javascript is enabled like so:

yourWebViewVariable.getSettings().setJavaScriptEnabled(true);

for Android 3.1 just add this to your java file onLoadInit:

CookieManager.setAcceptFileSchemeCookies(true);   //This is the line that specifically makes it work so the other lines is optional

CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.acceptCookie();

回答1:


For those interested, I figured it out. It is not a Childbrowser issue at all. You have to make the parent Phonegap project accept local cookies and then Childbrowser will too. To do so, You should have a file called youappname.java in your PhoneGap project, probably with this contents or similar:

import android.os.Bundle;
import org.apache.cordova.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
}
}

Modify it to look like this example:

import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    CookieManager.setAcceptFileSchemeCookies(true);
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
}
}


来源:https://stackoverflow.com/questions/10639563/adding-cookiemanager-to-android-childbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!