How to enable cookies for Android phonegap 1.8.0 app?

后端 未结 3 818
臣服心动
臣服心动 2020-12-15 14:43

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

When building phonegap for iOS using xcode 4 th

3条回答
  •  旧时难觅i
    2020-12-15 15:24

    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");
    }
    }
    

提交回复
热议问题