andriod之应用内置浏览器 webview
参考:http://my.eoe.cn/694183/archive/10476.html
http://blog.csdn.net/it_ladeng/article/details/8136534
一.webView获取html页面中标签的方法:
1.在WebViewClient里的onPageFinished回调方法中执行js代码:
view.loadUrl("javascript:console.log('MAGIC'+document.getElementById('wxImg')['src']);");
2.在WebChromeClient里的onConsoleMessage回调方法中截取LOG信息:
@Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) {if (consoleMessage.message().startsWith("MAGIC")) {String msg = consoleMessage.message().substring(5); // strip off prefixcom.youku.util.Logger.d("dazhu_IntegratedWebView", "msg : " + msg);if (!TextUtils.isEmpty(msg)) {if (oritationChangeActivity != null)oritationChangeActivity.setReceiveImage(msg);}return true;}return super.onConsoleMessage(consoleMessage); }
二.支持缩放,电脑网页适配手机屏幕
// 支持缩放 wb.getSettings().setBuiltInZoomControls(true); wb.getSettings().setSupportZoom(true); // 电脑网页最小化适配手机屏幕 wb.getSettings().setUseWideViewPort(true); wb.getSettings().setLoadWithOverviewMode(true);
三.app与webview共用cookie.前提访问网络用的是HttpURLConnection。
private void initCookie() {android.webkit.CookieSyncManager.createInstance(this);// unrelated, just make sure cookies are generally allowedandroid.webkit.CookieManager.getInstance().setAcceptCookie(true);// magic starts hereWebkitCookieManagerProxy coreCookieManager = new WebkitCookieManagerProxy(null, java.net.CookiePolicy.ACCEPT_ALL);java.net.CookieHandler.setDefault(coreCookieManager);}
public class WebkitCookieManagerProxy extends CookieManager {private android.webkit.CookieManager webkitCookieManager;public WebkitCookieManagerProxy(){this(null, null);}public WebkitCookieManagerProxy(CookieStore store, CookiePolicy cookiePolicy){super(null, cookiePolicy);this.webkitCookieManager = android.webkit.CookieManager.getInstance();}@Overridepublic void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException{// make sure our args are validif ((uri == null) || (responseHeaders == null)) return;// save our url onceString url = uri.toString();// go over the headersfor (String headerKey : responseHeaders.keySet()){// ignore headers which aren't cookie relatedif ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;// process each of the headersfor (String headerValue : responseHeaders.get(headerKey)){this.webkitCookieManager.setCookie(url, headerValue);}}}@Overridepublic Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException{// make sure our args are validif ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");// save our url onceString url = uri.toString();// prepare our responseMap<String, List<String>> res = new java.util.HashMap<String, List<String>>();// get the cookieString cookie = this.webkitCookieManager.getCookie(url);// return itif (cookie != null) res.put("Cookie", Arrays.asList(cookie));return res;}@Overridepublic CookieStore getCookieStore(){// we don't want anyone to work with this cookie store directlythrow new UnsupportedOperationException();} }
参考:http://stackoverflow.com/questions/18057624/two-way-sync-for-cookies-between-httpurlconnection-java-net-cookiemanager-and
转载于:https://www.cnblogs.com/fanglove/p/3502091.html
andriod之应用内置浏览器 webview相关推荐
- 安卓系统源码编译系列(六)——单独编译内置浏览器WebView教程
原文 http://blog.csdn.net/zhaoxy_thu/article/details/18883015 本文主要对从安卓系统 ...
- android webview定位权限,混合开发安Android webview使用内置浏览器定位的权限
具体步骤: 一.添加权限: 二.设置webview.setting WebSettings settings = webView.getSettings(); settings.setGeolocat ...
- Android开发实用小技巧九——内嵌WebView的使用(内置浏览器)
文章目录 前言 一.效果展示 二.代码 1.样式布局 2.活动页面 总结 前言 内嵌WebView的使用(内置浏览器). 一.效果展示 二.代码 1.样式布局 res/layout/activity_ ...
- 微信内置浏览器的JsAPI(WeixinJSBridge续)[转载]
原文地址: http://www.baidufe.com/item/f07a3be0b23b4c9606bb.html 之前有写过几篇关于微信内置浏览器(WebView)中特有的Javascript ...
- php http_user_agent 微信浏览器改变为其他浏览器,微信内置浏览器HTTP_USER_AGENT
随着微信的普及和微信公众号的营销日益增多,我们所面对的开发不再仅仅局限于传统的网站,微信开发也成为了我们程序猿的一项必修课程. 我们可以借助微信开发者工具进行微信小程序和微信公众号网页开发,但是在微信 ...
- 关于内置浏览器的问题
============问题描述============ 程序内置了admob广告条(或其它广告条) 如果我想客户点击广告的时候 在我程序内置的浏览器打开网页 该怎么实现呢 谢谢!!!!!!!!!!! ...
- 微信小程序跳转微信内置浏览器
最近遇到一个需求,需要微信小程序跳转到微信内置浏览器,但是官网并没有给出相关文档.查阅了大量资料,发现有两种实现方式. 1.通过微信公众号文章实现 小程序可以使用web-view打开关联的公众号文章, ...
- iOS 模拟微信内置浏览器CYWebViewController
iOS 模拟微信内置浏览器和Safari浏览器CYWebViewController 分为两种模式,一种是类似微信内置浏览器模式,一种是Safari浏览器模式.类似微信内置浏览器,顶部导航栏提供web ...
- 安卓非微信内置浏览器中的网页调起微信支付的方案研究
问题来源 之前在app中集成过微信支付,此种微信支付方式为app支付,即在我们自己的应用中嵌入微信支付SDK,由Native代码调起微信支付. 后来由于业务需要在我们app的WebView中打开第三方 ...
最新文章
- Frighting的日常:第6天
- [Java基础]判断字符串指定字符类型
- sql去除重复语句(转)
- Java后端,应该日常翻看的中文技术网站
- SAP Fiori Elements 应用里的 Title 显示的内容是从哪里来的
- [flask 优化] 由flask-bootstrap,flask-moment引起的访问速度慢的原因及解决办法
- 架构设计(3)---架构师到底要做什么,他们需要掌握些什么?
- 经典排序算法(二)--桶排序Bucket Sort
- 用AXIS2发布WebService的方法 使用eclipse插件生成服务端和客户端
- 定时器 Cron表达式
- 带给人类最大力量的,不是仇恨,而是人性--《看见》读后感
- Google开源项目Python 语言规范
- C++如何写adaptable仿函数
- Android与H5相互接口调用及Android端接口整理
- php中如何插入图片,php如何添加图片
- 光纤传感器实验模块_光纤传感器位移特性实验
- Done、Doing、ToDo
- 景联文科技:为自动驾驶车载语音识别技术提供全方面的数据支持
- 纽约证监会主席命令SPAC借壳上市必须严格监管: 推荐新的投资者保护措施
- 《图解数据结构》(第二版)读书笔记
热门文章
- 讲字节数组转化为base64_Base64编码简介及简单实现
- 还在用 Notepad++吗? 盘点五款更好用的文本编辑器
- 网络进阶:用了HTTPS就安全了吗?HTTPS 会被抓包吗?
- 如何让你的 JS 写得更漂亮,看这篇就对了!
- php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网
- java 程序是由什么组成的 java_从零开始的JAVA -2. java程序的构成及命名规则
- 计算机网络实验11.6.1,6.111 2004春季课程:数位系统概论实验(Introductory Digital Systems Laboratory, Spring 2004)...
- nginx php7提速,nginx+php7-fpm 性能提升几倍跟踪实践结果并优化
- 视觉感知_产品设计中的视觉感知
- ar软件测试工具_如何为用户测试制作快速的AR原型