添加CookieManager到Android Childbrowser [英] Adding CookieManager to android Childbrowser
问题描述
我试图让当地的饼干(文件://)在Android 3.1+工作
内ChildBrowser。我发现了一个博客回应谈论这
具体问题以及如何使用Cookie管理器来补救。我不能
找出其中的插件把code。有没有人
成功实施呢?
HTTP下面的评论:// code .google.com / p /安卓/问题/细节?ID = 3739
由edtechk ... @ gmail.com,2012年2月1日评论16
我得到这个东西的工作,为Android 2.2,JavaScript的
的document.cookie工作正常,只要确保在你的
的WebView ... JavaScript是像这样启动:
yourWebViewVariable.getSettings()setJavaScriptEnabled(真)。
针对Android 3.1只是添加到您的Java文件调用onLoadInit:
CookieManager.setAcceptFileSchemeCookies(真); //这是专门使得它的工作让其他线路线路可选CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(真);
cookieManager.acceptCookie();
对于那些有兴趣,我理解了它。这根本不是一个问题Childbrowser。你必须让父母的PhoneGap项目接受本地cookie,然后Childbrowser也会。
要做到这一点,你应该有一个名为youappname.java在你的PhoneGap项目文件,可能与该内容或类似的:
进口android.os.Bundle;
导入org.apache.cordova *。公共类应用扩展DroidGap {
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
super.loadUrl(文件:///android_asset/www/index.html);
}
}
修改它看起来像这样的例子:
进口android.os.Bundle;
进口android.webkit.CookieManager;
导入org.apache.cordova *。公共类应用扩展DroidGap {
/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
CookieManager.setAcceptFileSchemeCookies(真);
super.onCreate(savedInstanceState);
super.loadUrl(文件:///android_asset/www/index.html);
}
}
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();
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");
}
}
这篇关于添加CookieManager到Android Childbrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!