如何启用Cookie为Android 1.8.0的PhoneGap应用程序? [英] How to enable cookies for Android phonegap 1.8.0 app?

查看:290
本文介绍了如何启用Cookie为Android 1.8.0的PhoneGap应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解,为了使用Cookie的PhoneGap的本机应用程序内必须有一张code这使得它。

I understood that in order to use cookies inside of phonegap native app there must be piece of code which enables it.

当构建的PhoneGap为用x code 4的iOS有这样一块code PhoneGap的模板内。

When building phonegap for iOS using xcode 4 there is such piece of code inside of phonegap template.

能否请你指点我哪code和,我需要整理启用Cookie为Android 1.8.0的PhoneGap应用程序?

Could you please advice me which code and where I need to put in order to enable cookies for Android phonegap 1.8.0 app?

请注意,我使用了Eclipse 3.7.2靛蓝的应用程序的构建。

Please note that I'm using the eclipse Indigo 3.7.2 for building of the app.

非常感谢。

干杯, 米哈伊。

推荐答案

如果您要使用本地饼干(文件://)你必须做出父的PhoneGap项目接受本地的cookies。要做到这一点,你应该有一个名为youappname.java在你的PhoneGap项目文件,可能与该内容或相似的:

If you are trying to use local cookies (file://) you have to make the parent Phonegap project accept local cookies. 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");
}
}

这篇关于如何启用Cookie为Android 1.8.0的PhoneGap应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆