webview cookie is android webview 是什么意思
答案:2 悬赏:20
解决时间 2021-12-22 17:57
- 提问者网友:wodetian
- 2021-12-22 10:59
webview cookie is android webview 是什么意思
最佳答案
- 二级知识专家网友:冷眼_看世界
- 2021-12-22 12:31
web view cookie is android web view 意思:网页查看的是安卓网页的视图
词汇解释
view 英 [vju:] 美 [vju]
n.看法;风景;视域;[建筑学]视图
vt.看;看待
例句
1、Washington and Moscow are believed to have similar views on Kashmir
据信华盛顿和莫斯科在克什米尔问题上的看法相似。
2、He stood up to get a better view of the blackboard
为了更清楚地看到黑板上的内容,他站了起来。
词汇解释
view 英 [vju:] 美 [vju]
n.看法;风景;视域;[建筑学]视图
vt.看;看待
例句
1、Washington and Moscow are believed to have similar views on Kashmir
据信华盛顿和莫斯科在克什米尔问题上的看法相似。
2、He stood up to get a better view of the blackboard
为了更清楚地看到黑板上的内容,他站了起来。
全部回答
- 1楼网友:转身后的回眸
- 2021-12-22 14:04
在app中嵌入网页,使用nativie方式登录,然后将cookie保存到webview中,实现免登录功能。同步cookie到webview的方法可以参考下面的代码:
private void synccookie(context context, string url){
try{
log.d("nat: webview.synccookie.url", url);
cookiesyncmanager.createinstance(context);
cookiemanager cookiemanager = cookiemanager.getinstance();
cookiemanager.setacceptcookie(true);
cookiemanager.removesessioncookie();// 移除
cookiemanager.removeallcookie();
string oldcookie = cookiemanager.getcookie(url);
if(oldcookie != null){
log.d("nat: webview.synccookieoutter.oldcookie", oldcookie);
}
stringbuilder sbcookie = new stringbuilder();
sbcookie.append(string.format("jsessionid=%s","input your jsessionid string"));
sbcookie.append(string.format(";domain=%s", "input your domain string"));
sbcookie.append(string.format(";path=%s","input your path string"));
string cookievalue = sbcookie.tostring();
cookiemanager.setcookie(url, cookievalue);
cookiesyncmanager.getinstance().sync();
string newcookie = cookiemanager.getcookie(url);
if(newcookie != null){
log.d("nat: webview.synccookie.newcookie", newcookie);
}
}catch(exception e){
log.e("nat: webview.synccookie failed", e.tostring());
}
}
使用上面的方法可以将cookie同步到webview中,这样浏览网页时即可实现免登录。
但是在实际使用过程中会出现cookie并未保存成功,每次都会跳转到登录页面应为初始化webview时漏掉了重要的东西。可以参考下面代码设置webview。
private void initwebviewsettings(){
// mywebview.getsettings().setsupportzoom(true);
// mywebview.getsettings().setbuiltinzoomcontrols(true);
// mywebview.getsettings().setdefaultfontsize(12);
// mywebview.getsettings().setloadwithoverviewmode(true);
// 设置可以访问文件
mywebview.getsettings().setallowfileaccess(true);
//如果访问的页面中有javascript,则webview必须设置支持javascript
mywebview.getsettings().setjavascriptenabled(true);
mywebview.getsettings().setuseragentstring(myapplication.getuseragent());
mywebview.getsettings().setcachemode(websettings.load_no_cache);
mywebview.getsettings().setallowfileaccess(true);
mywebview.getsettings().setappcacheenabled(true);
mywebview.getsettings().setdomstorageenabled(true);
mywebview.getsettings().setdatabaseenabled(true);
}
完成以上两步操作,再次运行程序,就会发现,打开网页后不会再跳转到登录页面了。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯