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 prefix
com.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 allowed
android.webkit.CookieManager.getInstance().setAcceptCookie(true);
// magic starts here
WebkitCookieManagerProxy 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();
} @Override
public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException
{
// make sure our args are valid
if ((uri == null) || (responseHeaders == null)) return; // save our url once
String url = uri.toString(); // go over the headers
for (String headerKey : responseHeaders.keySet())
{
// ignore headers which aren't cookie related
if ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue; // process each of the headers
for (String headerValue : responseHeaders.get(headerKey))
{
this.webkitCookieManager.setCookie(url, headerValue);
}
}
} @Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException
{
// make sure our args are valid
if ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null"); // save our url once
String url = uri.toString(); // prepare our response
Map<String, List<String>> res = new java.util.HashMap<String, List<String>>(); // get the cookie
String cookie = this.webkitCookieManager.getCookie(url); // return it
if (cookie != null) res.put("Cookie", Arrays.asList(cookie));
return res;
} @Override
public CookieStore getCookieStore()
{
// we don't want anyone to work with this cookie store directly
throw new UnsupportedOperationException();
}
}
参考:http://stackoverflow.com/questions/18057624/two-way-sync-for-cookies-between-httpurlconnection-java-net-cookiemanager-and
andriod之应用内置浏览器 webview的更多相关文章
- appium常见问题04_查看andriod内置浏览器webview版本
方法一:手机上设置中查看 设置-->应用程序管理-->全部-->Android System WebView 方法二:adb指令查看(前提,已安装android sdk环境) 1,w ...
- 安卓系统源码编译系列(六)——单独编译内置浏览器WebView教程
原文 http://blog.csdn.net/zhaoxy_thu/article/details/18883015 本文主要对从 ...
- 非内置浏览器WebView 调起H5支付,提示商家参数格式有误
微信H5 支付开发官方文档参考资料: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_4 0. 场景描述:在APP 中使用webVie ...
- 微信内置浏览器WebApp开发,踩坑 · Issue #31 · maxzhang/maxzhang.github.com · GitHub
最近花6天时间完成了一个七夕的小活动,是一个简单的WebApp.由于我前期对面向微信的Web开发评估不足,导致开发过程十分艰难.写这篇文章总结下,惊醒自己未来不要再犯这样的错误. 问题: 1. 有些比 ...
- 微信内置浏览器的JsAPI(WeixinJSBridge续)[转载]
原文地址: http://www.baidufe.com/item/f07a3be0b23b4c9606bb.html 之前有写过几篇关于微信内置浏览器(WebView)中特有的Javascript ...
- 开源的Android开发框架-------PowerFramework使用心得(三)内置浏览器BrowserActivity
使用内置浏览器必须是引用源码的方式(因为jar中不能打包布局文件等资源).内置浏览器是一个继承自BaseActivity的普通Activity,使用WebView实现. 1.简单的打开内置浏览器 In ...
- 微信内置浏览器的JsAPI(WeixinJSBridge续)_Alien的笔记
微信内置浏览器的JsAPI(WeixinJSBridge续)_Alien的笔记 微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏 之前有写过几篇关于微信内置浏览器(WebView) ...
- 【原创+亲测可用】JS如何区分微信浏览器、QQ浏览器和QQ内置浏览器
1.原理: 通过不同移动端的ua弹窗 获取user-agent 参数包含的信息,进行判断浏览器类型 在Android上 QQ内置环境的ua中有关键字 MQQBrowser, 并且后面包含一个[空白符+ ...
- 微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏
微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏 之前有写过几篇关于微信内置浏览器(WebView)中特有的Javascript API(Javascript Interface) ...
随机推荐
- css3 loading效果
file:///E:/zhangqiangWork/2014/SPDbank/index.html 参考该网站 http://tobiasahlin.com/spinkit/ 查看源代码把里面的dom ...
- Java学习-040-级联删除目录中的文件、目录
之前在写应用模块,进行单元测试编码的时候,居然脑洞大开居然创建了一个 N 层的目录,到后来删除测试结果目录的时候,才发现删除不了了,提示目录过长无法删除.网上找了一些方法,也找了一些粉碎机,都没能达到 ...
- 网站启动SSL, http变为https后,session验证码错误解决方法
网站启动SSL, http变为https后,session验证码错误解决方法 最近公司需要后台启动安全证书,证书安装完毕后,后台老提示 验证码错误,经过几天的研究,此问题已经得到有效解决,现把方法 ...
- SQL判断字符串里不包含字母
Oracle: 方法一:通过To_Number 函数异常来判断,因为这个函数在转换不成功的时候是报错,所以只能用存储过程包装起来. CREATE OR REPLACE FUNCTION Is_Numb ...
- js实例代码
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Windows 上使用 cygwin 连接到 docker toolbox
Windows 上使用 cygwin 连接到 docker toolbox Docker 确实给软件开发带来一些好处,在简化部署.统一开发.测试和生产环境上,有它独到的理念.Linux 上可直接安装 ...
- ucenter 整合同步登录的内部实现原理及thinkphp整合ucenter
1.用户登录discuz,通过logging.php文件中的函数uc_user_login对post过来的数据进行验证,也就是对username和password进行验证.2.如果验证成功,将调用位于 ...
- JSP常用标签——JSTL标签和EL表达式
一.JSTL简介 1.什么是JSTL JSTL是Java中的一个定制标记库集.(这个标记库集不需要自己编写,可以直接使用) 2.为什么要使用JSTL 实现了JSP页面中的代码复用(基于标签库原理,重复 ...
- jiffies和HZ
全局变量jiffies用来记录自系统启动以来产生的节拍的总数.启动时,内核将该变量初始化为0,此后,每次时钟中断处理程序都会增加该变量的值.一秒内时钟中断的次数等于Hz,所以jiffies一秒内增加的 ...
- session的方法
Hibernate对象的状态 瞬时(Transient) — 由 new 操作符创建,且尚未与Hibernate Session 关联的对象被认定为瞬时(Transient)的.瞬时(Transien ...