参考: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. js判断input为空校验

    突然发现最近js发现的问题比较多,更发现我怎么快成了前端开发了?不能够啊!我后台怎么不出问题呢?我的后台是太简单了吗?mybatis-dao-service-controller返回给前台...... ...

  2. ajax处理回调函数,用ajax向后台发送数据

    这是我的后台返回给前台的数据: 处理后台返回的数据有一下两种方式: function sethouse_housing_pattern(housing_pattern){ var str=[]; va ...

  3. 获得输入框的文本document.getElementById('id').value;

    <input id="demo" type="text" value="" > x=document.getElementByI ...

  4. 将option添加到select框

    var select=document.createElement("select"); select.setAttribute("class","f ...

  5. APP源码集中打包大放送!十一个千万级别APP源码随意处置!

    小伙伴们还在一个一个苦苦寻找各类APP源码吗?此贴集中打包最常用APP的源码,你想得到的APP,这里都有! 想做商城?这里有天猫! 想做同城服务?这里有大众点评! 想做外卖?这里有饿了么! 想做视频? ...

  6. 安装和删除 Alcatraz 插件

    在终端下输入如下命令来安装Alcatraz: curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install. ...

  7. Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?

    org.springframework.http.client.SimpleClientHttpRequestFactory java.net.Proxy java.net.Proxy.Type ja ...

  8. HBase -- 基于HDFS的开源分布式NoSQL数据库

    HBase(Hadoop Database)是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,我们可以利用HBase技术在廉价的PC上搭建起大规模结构化存储集群.同Google的Bigtable ...

  9. Android 开发环境搭建以及编译

    两种搭建编译环境的方式,一种方法是用户安装虚拟机,然后安装基础的Ubuntu12.04.2 系统,利用提供的工具和详细的使用步骤,搭建编译环境:另外一种方法是用户安装虚拟机,然后直接加载 “搭建好的U ...

  10. Leetcode: Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...