android webview里设置cookie

Android Okhttp框架webView设置Cookie无效问题 OKhttp框架再熟悉不过了,不过今天遇到一个坑,先记录一下: OKhttp要自定义管理Cookie时,要继续CookieJar去定义。 这是管理的原理: Android OkHttp的Cookie自动化管理 这是如何设置到webView:用Okhttp框架登录之后的Cookie设置到webView中 用了上面博客的方法设置了cookie,发现二个坑: 1.用户切换账号无效,就 阅读详情
我们在android中访问网络经常会用到Apache的HttpClient,用此类去访问网络获取数据, 

但是在写android界面的时候又时不时的会用到一些WebView组件,这时候访问一个以经登录的页面的时候cookie设置就有个问题 

在HttpClient中保存下来的Cookie怎么设置到WebView组件里,让WebView也保持住Cookie状态,也就是登录状态呢? 

CookieSyncManager和CookieManager就是做这种事的,下面来看代码里怎么设置Cookie让WebView也保持登录状态: 

Java代码   收藏代码
  1. /** 
  2.  * 同步一下cookie 
  3.  */  
  4. public static void synCookies(Context context, String url) {  
  5.     CookieSyncManager.createInstance(context);  
  6.     CookieManager cookieManager = CookieManager.getInstance();  
  7.     cookieManager.setAcceptCookie(true);  
  8.     cookieManager.removeSessionCookie();//移除  
  9.     cookieManager.setCookie(url, cookies);//cookies是在HttpClient中获得的cookie  
  10.     CookieSyncManager.getInstance().sync();  
  11. }  

在android里面在调用webView.loadUrl(url)之前一句调用此方法就可以给WebView设置Cookie 

注:这里一定要注意一点,在调用设置Cookie之后不能再设置
Java代码   收藏代码
  1. webView.getSettings().setBuiltInZoomControls(true);  
  2. webView.getSettings().setJavaScriptEnabled(true);  

这类属性,否则设置Cookie无效。
YOLOv11改进策略【SPPF】| 将特征金字塔池化修改为:SPPCSPC,提升模型的特征提取能力和计算效率。 本文记录的是。YOLOv7中的SPPCSPC(Spatial Pyramid Pooling Cross Stage Partial Connections)模块是一种结合了(SPP)和(CSP)的改进结构,本文将其添加到YOLOv11中, 阅读详情

相关推荐

打包可以在Hadoop 3.3.1和Hive 3.1.2上使用的Tez 0.10.1 minimal

编译打包可以在Hadoop 3.3.1和Hive 3.1.2上使用的Tez 0.10.1

qq_42013533的博客 2618

个人日记—Android WebView 给URL添加cookie

Android WebView 给URL添加cookie

a215595580的博客 1099

电芯外观及体系设计(Cell Design)-①容量平衡设计(Cell Balance Design)

全面获取并正确解读客户需求,将需求进行分解和预判,结合公司现有资源、技术,给出设计方案。一个优秀的电芯设计方案,应该是稳健的,可操作的,满足客户需求的同时,并能为公司带来较多利润。电芯设计需同时考虑周期,性能,品质,加工性,成本,及安全与稳健性。设计人员时刻要有成本控制观念,但利润则是由公司战略所决定。

FDC1303864002的博客 1352

Android WebView 使用Authorization、Cookie

Android WebView 使用Authorization、Cookie。

顺着天赋做事,逆着性格做人 1273

微信小程序PC端兼容性实战:如何绕过限制在电脑上运行手机端小程序

本文详细解析了微信小程序在PC端的兼容性问题及解决方案,重点介绍了如何利用`wx.getSystemInfo`API检测运行环境,并通过修改User-Agent、动态环境检测与适配等技术手段实现手机端小程序在PC端的顺畅运行。文章还提供了常见兼容性问题的解决方法和调试工具推荐,帮助开发者高效应对多端适配挑战。

weixin_28366053的博客 867

ADS2023仿真变容二极管特性

仿真S-Param仿真控件,设置为Single Point,将频率设置为1MHz,同时勾选Z-parameters,取消S-parameters,从元件库中选择元器件搭建原理图,并根据器件spice提供的相关参数,对原理图中器件参数进行修改,修改完成的电路图如下图所示。添加var控件和MeasEqn控件,相关设置如图所示,Ct为变容管的电容值,Q0为其品质因数。因此,对变容二极管的模型仿真结果是可以信赖的。将其解压,在spice文件夹中,可以找到我们想要的器件参数,和仿真简要电路图。

weixin_45811090的博客 1万+

Android WebView设置Cookie

需求背景: 做项目中, h5那边需要android端给他们传cookie,所以就需要在webview里面同步cookie信息 设置: public static final void synchronousWebCookies(@NotNull Context context, @NotNull String url) { try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) .

weixin_41993823的博客 4045

组态王|以一定的时间间隔查询某个时间段内的历史数据

使用该函数其他都可以满足,唯一问题是变量的选择,当切换站点后查询历史数据时,所选的变量依然是上次站点查询时所选择的变量,每当更换站点查询时都需要重新选择变量,这一点太繁琐,是用户和操作者无法忍受的。但是由于现场可能数据变化并非太过频繁,想要实现记录频率不变,还是以1分钟一次的频率进行存储,但是报表查询的时候想要只显示整点的数据。其中日历控件的设置与之前的历史数据查询是一样的,报表的抬头设置都是不用变的,此处不再赘述,有兴趣的可以。以上为组态王中以一定的时间间隔查询某个时间段内的历史数据的实现过程。

做有价值的事,积累有价值的笔记! 2544

【WebView】Android WebView中的Cookie操作

Android给WebView设置Cookie的方法。

滴水穿石,点石为金 1万+

基于PLC的冲压件自动生产线电气系统设计【附数据】

考虑到生产线的高效运行和维护简便性,选择了三菱FX系列的可编程逻辑控制器(PLC)作为核心控制单元,该型号的PLC因其高可靠性和强大的功能集,在工业自动化领域有着广泛的应用。最后,在完成初步的软件开发后,进行了多轮次的模拟测试和现场调试,逐步修正了存在的问题,最终达到了预期的功能要求。例如,对于进料环节,选用了光电传感器以精确检测物料的位置;此外,为了适应不同尺寸的工件加工需求,还特别设计了一套可调节的夹具系统,不仅提高了生产线的灵活性,同时也降低了更换模具的成本。✅ 感恩科研路上每一位志同道合的伙伴!

lagougongzuoshi的博客 1292

三菱 FX5U PLC 4轴程序 控制松下伺服3个, 步进电机一个

三菱 FX5U PLC 4轴程序。 控制松下伺服3个, 步进电机一个, 四轴自动堆垛码垛设备程序, 回原点动作用专用的原点回归指令写的, 手动运行用三菱相对定位指令写的 , 自动运行用绝对定位指令写的取料运行, 表格定位写的自动放料运行, 设备各种报警异常都有写出 程序每一步都有注释。 包括PLC程序、显控触摸屏 程序、松下伺服驱动器接线图。 程序内都有IO注释 编号:4816635519484681汇美0808 ...

m0_68069172的博客 3381

android webview里获取和设置cookie

private class MyWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { webview.loadUrl(url); return true; ...

weixin_30823683的博客 220

智能制造之物料详解

制造业业务系统中的物料流转贯穿需求、采购、生产到交付全流程,各系统协同实现精准追踪。需求阶段由CRM/ERP/PLM生成物料计划;采购入库阶段SCM/WMS/QMS完成采购质检;生产阶段MES/APS协调领料加工;成品交付阶段WMS/SCM处理出库物流。整个流程以BOM为蓝图,ERP为调度中心,通过数据联动实现物料状态、位置和数量的全链路可追溯。

cdfunlove的博客 655

vue怎么让接口带上cookie_vue--设置cookie

Vue-CLI项目-vue-cookie与vue-cookies处理cookievue-cookie一.模块的安装npm install vue-cookie --save#--save可以不用写二.配置main.js// 配置cookieimport cookie from 'vue-cookie'Vue.prototype.$cookie = cookie; //配置时候prototype....

weixin_39850787的博客 1091

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Android 给WebView设置Cookie

最近项目中用到WebView访问新浪支付页面,有个要求是必须是登录状态,否则会报Token过期,然后我简单的将我从cookie中取得的ticket,即一串数字可以代表用户登录的唯一标识作为参数拼接到url路径上,竟然成功了,但是,当在新浪页面进入第二级界面的时候,还会报Token过期,这才意识到,还是新浪网页没有获取到cookie。 可是ios也是用的webview访问的新浪支付,并...

weixin_30517001的博客 104

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Android webView 获取、设置 cookie的方法

做android项目难免遇到这种情况,需使用webview加载网页,并且获取cookie。或者需要设置自己的请求cookie正常加载网页。下面分别介绍一下android 中 webview的使用方法。 1.获取url中的cookie: 方法一:我们需要自己写一个cookie管理类:MyWebViewClient public class MyWebViewClient exte...

zhichaosong的博客 6679

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android webview 设置cookie 保持登录状态

在项目开发中用webview加载html,用户在html里登录,需求是当用户杀掉进程重新进入App的时候要保持用户的登录状态,Android 原生的webview是不记录登录状态的,这时候需要我们进入页面的时候取出cookie,退出的时候在生命周期里存储cookie,网上找了很多资料才解决问题,特此记录一下,具体操作代码如下: //获取cookie 在刚进入页面的时候,获取到cookie后通过c...

虫逗蚊子的博客 7119

安卓学习笔记---AndroidWebview里设置Cookie遇到的坑

我们一般在使用WebView去加载H5界面的时候都会同步一下Cookie,一般的都会这么做: 在HttpClient中保存下来的Cookie怎么设置到WebView组件里,让WebView也保持住Cookie状态,也就是登录状态呢?  CookieSyncManager和CookieManager就是做这种事的,下面来看代码里怎么设置Cookie让WebView也保持登录状态:

紫色飞鱼儿的博客 2万+

Android WebView设置cookie

场景: Android原生和H5的混合开发中,登录维护在原生,某些详情页面嵌套Webview。 问题:原生登录之后将cookie存起来,在 WebView.loadUrl("");之前设置cookie,针对每个项目cookie它的格式都不相同。 如果你不知道你们url的cookie格式的话,你可以将url复制到pc端的浏览器中,打开开发者模式如...

JayRier的博客 2276

Android WebView—设置cookie

Android中WebView加载网页,有时候需要通过cookie向网页传递信息,如免登录保存登录状态等 设置cookie 在调用loadUrl(url);前一句调用以下synCookies()方法进行 Cookie 同步操作。 /** * 给WebView同步Cookie * * @param context 上下文 * @param url 可以使用[domain][host] */ public void synCookies(Context con..

三杯五岳 2065
上一篇: 按钮水波效果
下一篇: Android View绘制流程
coder_nice
博客等级 码龄12年 33粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值