参考: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的更多相关文章

  1. appium常见问题04_查看andriod内置浏览器webview版本

    方法一:手机上设置中查看 设置-->应用程序管理-->全部-->Android System WebView 方法二:adb指令查看(前提,已安装android sdk环境) 1,w ...

  2. 安卓系统源码编译系列(六)——单独编译内置浏览器WebView教程

    原文                   http://blog.csdn.net/zhaoxy_thu/article/details/18883015                 本文主要对从 ...

  3. 非内置浏览器WebView 调起H5支付,提示商家参数格式有误

    微信H5 支付开发官方文档参考资料: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_4 0. 场景描述:在APP 中使用webVie ...

  4. 微信内置浏览器WebApp开发,踩坑 · Issue #31 · maxzhang/maxzhang.github.com · GitHub

    最近花6天时间完成了一个七夕的小活动,是一个简单的WebApp.由于我前期对面向微信的Web开发评估不足,导致开发过程十分艰难.写这篇文章总结下,惊醒自己未来不要再犯这样的错误. 问题: 1. 有些比 ...

  5. 微信内置浏览器的JsAPI(WeixinJSBridge续)[转载]

    原文地址:  http://www.baidufe.com/item/f07a3be0b23b4c9606bb.html 之前有写过几篇关于微信内置浏览器(WebView)中特有的Javascript ...

  6. 开源的Android开发框架-------PowerFramework使用心得(三)内置浏览器BrowserActivity

    使用内置浏览器必须是引用源码的方式(因为jar中不能打包布局文件等资源).内置浏览器是一个继承自BaseActivity的普通Activity,使用WebView实现. 1.简单的打开内置浏览器 In ...

  7. 微信内置浏览器的JsAPI(WeixinJSBridge续)_Alien的笔记

    微信内置浏览器的JsAPI(WeixinJSBridge续)_Alien的笔记 微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏 之前有写过几篇关于微信内置浏览器(WebView) ...

  8. 【原创+亲测可用】JS如何区分微信浏览器、QQ浏览器和QQ内置浏览器

    1.原理: 通过不同移动端的ua弹窗 获取user-agent 参数包含的信息,进行判断浏览器类型 在Android上 QQ内置环境的ua中有关键字 MQQBrowser, 并且后面包含一个[空白符+ ...

  9. 微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏

    微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏 之前有写过几篇关于微信内置浏览器(WebView)中特有的Javascript API(Javascript Interface) ...

随机推荐

  1. css3常用动画效果集合01

    /*由右到左进场*/ .FromRightToLeft{ -webkit-animation:FromRightToLeft 500s .2s ease both; } @-webkit-keyfra ...

  2. Tram---poj1847(简单最短路)

    题目链接:http://poj.org/problem?id=1847 题意:给了N个交叉口,每个交叉口有自己能转到的交叉口. 注意这里:First number in the i-th line, ...

  3. Asp.net MVC中Route的理解

    在Asp.net MVC中,对于一个请求,是通过路由找到对应的Controller类中的对应Action,并与model进行交互,最后返回到view. 就是说Asp.net MVC是用Route来定义 ...

  4. iOS初级数据持久化 沙盒机制 归档与反归档

    数据持久化就是数据保存成文件,存储到程序中的沙盒中. 沙盒构成 Document 存储用户数据,需要备份的信息 Caches 缓存文件, 程序专用的支持文件 Temp 临时文件 通过代码查找程序沙盒的 ...

  5. windows 访问 ubuntu虚拟机 django服务器 失败

    配置ubuntu配置成桥接,在ubuntu虚拟机中运行django.py开发服务器.windows访问django失败. 虚拟机运行: python manage.py runserver 0.0.0 ...

  6. vs vim 插件

    需要在visual studio安装vim插件,由于在visual studio联机失败,只能手动下载安装. 转载自以下链接: http://blog.csdn.net/lingtianyulong/ ...

  7. http://blog.csdn.net/foreverling/article/details/51385128

    http://blog.csdn.net/foreverling/article/details/51385128

  8. 使用C语言把字母转换成大写,不能使用库函数

    char to_upper(char input) {   if ('a' <= input && input <= 'z') {     return input - ' ...

  9. js传值

    //传值$('.choose li').click(function(){    //alert('z');     $("#address").empty().prepend($ ...

  10. SQLServer temporary table and table variable

    Temporary tables are created in tempdb.  The name "temporary" is slightly misleading, for ...