使Android WebView不存储cookie或密码
我使用 Android WebView for Twitter OAuth:Twitter 要求用户登录并授权应用程序,我检索访问令牌并将其保留在我的应用程序中。
我不需要(也不)存储用户密码,但 WebView 保留 Twitter 的 cookie,并且还会询问用户是否希望它记住密码。因此,即使在通过他的 Twitter 帐户页面取消对应用程序的授权,并且我的应用程序销毁了访问令牌之后,下次打开 WebView 时,它可能仍然处于登录状态,即使没有,它也已登录密码框已填满。
如何强制 WebView 不要求记住密码,也不保留会话 cookie? 如果这是不可能的,我可以删除其所有存储的状态(图像缓存除外)吗?
I use an Android WebView for Twitter OAuth: Twitter asks the user to log in and authorize the application, I retrieve the access token and persist it in my application.
I have no need (and do not) store the user password, but the WebView keeps Twitter's cookies around, and it also asks the user if he wants it to remember the password. As a result of this, even after the de-authorizes the application via his Twitter account page, and my application destroys the access tokens, the next time the WebView is opened, it is probably still logged in, and even if not, it has the password box already filled.
How can I force WebView to not ask to remember passwords, and to not persist session cookies?
If that is not possible, can I delete all its stored state (except maybe the image cache)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用它来阻止存储 cookie 并清除已存储的 cookie:
You can use this to prevent cookies from being stored and clean cookies already stored:
对于不保存密码:
对于 cookie:
我不太确定 cookie 的实现。
For not saving passwords:
For cookies:
I am not very sure for the cookies implementation.
这是我在这方面看到的最好的答案
This is the best answer I have seen in this context
在一行中,试试这个。我认为这应该在启动 webview 后调用。
In one line, Try this. I think this should be called after starting the webview.
不要清除cookie,因为它会影响其他会话,如facebook等。存储在cookie内,所以尝试遵循此方法
在oauth事务之前,例如在webview创建之前
在oauth事务之后让通过设置接受cookie
它将工作我已经测试过它..
Don't clear cookies beacause it will effect other sessions like facebook etc.. stored inside the cookie so try to follow this method
Before oauth transaction such as before the webview creation
After oauth transaction let accept cookie by setting
it will work i have tested it..
我使用了以下解决方案:
以下方法对我不起作用:
可能的原因可能是我们没有同步 cookie,如下所示:
但这可能需要时间。
强制
WebView
不要求记住密码也不起作用。而且它也不利于可用性。
I have used following solution:
Following method does not worked for me:
A possible reason may be that we have not synced the cookies as following:
But it may be taking time.
Forcing
WebView
to not ask to remember passwords will also not work.And it is also not good for usability.