如何启用Cookie为Android 1.8.0的PhoneGap应用程序?应用程序、Android、Cookie、PhoneGap

2023-09-04 23:14:35 作者:卑微の誓言

我了解,为了使用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");
}
}