饼干和放大器; web视图

编程入门 行业动态 更新时间:2024-10-10 06:13:37
本文介绍了饼干和放大器; web视图 - CookieSyncManager在Android中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个活动,可以让您登录到一个页面。在接下来的活动它应该显示基于该Cookie网页如果登录成功。 该Cookie retrived,我要尽量把它放在web视图具有以下code:

I have an activity that lets you sign in to a page. In the next activity it should display a webpage based on the cookie if the login was successful. The cookie is retrived and I try to put it on the webView with the following code:

Cookie sessionCookie = LoginWebView.cookie; CookieSyncManager.createInstance(webview.this); CookieManager cookieManager = CookieManager.getInstance(); if (sessionCookie != null) { cookieManager.removeSessionCookie(); String cookieString = sessionCookie.getName() + "=" + sessionCookie.getValue() + "; domain=" + sessionCookie.getDomain(); Log.v(TAG, "COOKIE SYNC: " + cookieString); cookieManager.setCookie(domain, cookieString); CookieSyncManager.getInstance().sync(); } webView.setWebViewClient(new MyWebViewClient ()); webView.loadUrl("a_page/getpageiphone.aspx?p=home");

这是losely基于其他的问题在这里的StackOverflow code,但是当我加载网页它似乎并没有工作。它似乎有一些非常错误的与我的code,但我看不到的地方,我开始觉得我做的事情非常错误的。

This is losely based on code from other questions here on StackOverflow, but when I load the web-page it does not seem to work. It seems as there is something very wrong with my code but I can't see where and I'm starting to think I'm doing something very wrong.

推荐答案

您已经使用该行 -

You have used this line -

if (sessionCookie != null) { cookieManager.removeSessionCookie(); }

。 为确保您收到新的Cookie每次。

. To ensure you receive new cookie everytime.

好像你通过同样的问题已经如我面对,请查看以下链接 -

Seems like you have gone through same issue as I faced, check below link -

removeSessionCookie()发布的Andr​​oid(code.google)

它说, removeSessionCookie()在一个线程中实现,所以每当它被称为;一个线程启动后您 setCookie方法(URL,cookieString); 被调用时,它会删除你刚才设置的新的cookie。 因此,对于一些设备它的工作原理以及 removeSessionCookie()已经执行,而对于一些人来说,删除cookie中,我们得到了这个问题。

it says that removeSessionCookie() is implemented in a thread, so whenever it is called; a thread starts and after your setCookie(url, cookieString); is called, it removes the new cookie you just set. So for some devices it works well as removeSessionCookie() is already executed, while, for some, it remove the cookie, and we get that problem.

使用 SystemClock.sleep(500); ,你只是给系统完成removeSessionCookie()首先

by using SystemClock.sleep(500); , you just gave system to finish removeSessionCookie() first

我建议你删除此 removeSessionCookie(); 因为你是只设置一个cookie中,所以不会与其他饼干冲突。您的code无缝工作。

I suggest you remove this removeSessionCookie(); as you are setting only one cookie, so it won't conflict with other cookies. Your code will work seamlessly.

更多推荐

饼干和放大器; web视图

本文发布于:2023-11-28 18:56:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643574.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放大器   视图   饼干   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!