科尔多瓦会话cookie不会在Android棒棒糖工作会在、棒棒糖、科尔、多瓦

由网友(Coquettish妖艳)分享简介:我开发一个科尔多瓦/ PhoneGap的应用程序为Android其使用会话cookie登录到第三方网站。对于这一点,我做一个AJAX POST请求(使用jQuery),然后cookie被自动设定。I develop a Cordova/Phonegap app for Android which uses sess...

我开发一个科尔多瓦/ PhoneGap的应用程序为Android其使用会话cookie登录到第三方网站。 对于这一点,我做一个AJAX POST请求(使用jQuery),然后cookie被自动设定。

I develop a Cordova/Phonegap app for Android which uses session cookies to login to third party websites. For this, I do an AJAX post request (with jQuery) and then cookies are set automatically.

但是,当我更新了我的智能手机到Android 5.0棒棒糖,也是应用程序库API级别21,饼干停止工作。发生了什么变化?

But, when I updated my smartphone to Android Lollipop 5.0 and also the app libraries to API level 21, cookies stopped working. What has changed?

推荐答案

在互联网上的时间找我碰到解释真的很好的问题的文章一个有效的解决方案,所以我认为这将是对其他堆栈溢出有用用户张贴在这里。

After hours on the Internet looking for a working solution I came across an article that explains really well the issue, so I thought it would be useful for other Stack Overflow users to post it here.

基本上,问题就出在新的Andr​​oid第三方Cookie政策(https://developer.android.com/about/versions/android-5.0-changes.html#BehaviorWebView),这阻止他们在默认情况下。

Basically, the problem lies on the new Android third party cookies policy (https://developer.android.com/about/versions/android-5.0-changes.html#BehaviorWebView), which blocks them by default.

该解决方案很简单,只要加入code几行的主要活动:

The solutions is as simple as adding a few lines of code to the main activity:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.init();

    // Allow third party cookies for Android Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        WebView webView = (WebView)super.appView;
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView,true);
    }

    super.loadUrl(Config.getStartUrl());
}

有关详细信息,我把一个链接在这里完整的文章:http://joashpereira.com/blog/2014/11/19/fix-to-cordovaphonegap-apps-targeting-android-5-lollipop-or-later-on-default-disallowing-third-party-cookies/

For more information, I put a link to the full article here: http://joashpereira.com/blog/2014/11/19/fix-to-cordovaphonegap-apps-targeting-android-5-lollipop-or-later-on-default-disallowing-third-party-cookies/

阅读全文

相关推荐

最新文章