日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

andriod之应用内置浏览器 webview

發布時間:2023/12/9 HTML 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。