我在百川sdk的旺旺群中,追问这个问题N多次,一直没有人答复,哎,凡事都要靠自己.....

1、先查看下百川sdk中,是怎么处理咱们传递过去的 WebViewClient

public class l implements WebViewService {
private static final String b = l.class.getSimpleName();
private static final String c;
private static final String d;
private String e;
public static boolean a;
private String f = "";
private String g;
private HashMap<String, String> h = new HashMap(); public l() {
} public void bindWebView(WebView var1, WebViewClient var2) {
if(var1 != null) {
a = false;
WebSettings var5 = var1.getSettings(); try {
var5.setJavaScriptEnabled(true);
} catch (Exception var7) {
;
} var5.setSavePassword(false);
var5.setUseWideViewPort(true);
var5.setLoadWithOverviewMode(true);
var5.setJavaScriptCanOpenWindowsAutomatically(false);
var5.setDomStorageEnabled(true);
this.g = var1.getContext().getApplicationContext().getDir("cache", ).getPath();
var5.setAppCachePath(this.g);
var5.setAllowFileAccess(true);
var5.setAppCacheEnabled(true);
if(CommonUtils.isNetworkAvailable(var1.getContext())) {
var5.setCacheMode(-);
} else {
var5.setCacheMode();
} var5.setBuiltInZoomControls(false);
StringBuilder var6 = new StringBuilder();
this.e = var5.getUserAgentString();
if(this.e != null) {
var6.append(this.e);
} if(!WebViewUtils.isLoginDowngraded()) {
var6.append(d);
} var6.append(c);
var5.setUserAgentString(var6.toString());
if(VERSION.SDK_INT >= ) {
CookieManager.getInstance().setAcceptThirdPartyCookies(var1, true);
int var10000 = d.e == null?-:d.e.getIntValue("mixedContentMode", -);
int var8 = var10000;
if(var10000 != -) {
var5.setMixedContentMode(var8);
}
} if(var2 == null) {
var1.setWebViewClient(new m(this));
} else {
var1.setWebViewClient(new n(this));
}
}
} public void releaseWebView(WebView var1) {
var1.getSettings().setUserAgentString(this.e);
d.m.removeCookies();
} protected static void a(String var0) {
if(!WebViewUtils.isLoginDowngraded()) {
try {
CookieManagerWrapper.INSTANCE.refreshCookie(var0);
} catch (Exception var1) {
AliSDKLogger.e("ui", "fail to refresh cookie", var1);
}
}
} static {
c = " AliApp(BC/" + ConfigManager.TAE_SDK_VERSION.toString() + ")";
d = " tae_sdk_" + ConfigManager.SDK_INTERNAL_VERSION;
a = false;
}
}

关键在 bindWebView(WebView var1, WebViewClient var2) 方法中 var2 做了些什么!!...

if(var2 == null) {
var1.setWebViewClient(new m(this));
} else {
var1.setWebViewClient(new n(this));
}

哇擦擦,只是用来判断,连基本的保存都没有。可想我的 WebViewClient  死的多惨。

既然百川不带咱们的 WebViewClient  玩,那就想想其他办法,它不带咱们玩,那就咱们带它玩吧....

那怎么玩呢?咱们的 WebViewClient 来包裹百川的 WebViewClient ,然后在通过 webView.setWebViewClient 方法把新的 WebViewClient  重新设置进去。  

具体实现如下

1、首先绑定百川的 WebView 服务

mWebViewService = AlibabaSDK.getService(WebViewService.class);
mWebViewService.bindWebView(webView, null);

2、通过反射从系统的 WebView 获得百川的 WebViewClient

/** 获得隐藏成员变量mProvider中的WebViewClient */
public WebViewClient getProviderWebViewClient() {
WebViewClient webViewClient = null;
try {
Class<?> cls = this.getClass();
Method method = cls.getMethod("getWebViewProvider");
method.setAccessible(true);
Object object = method.invoke(this); // object => WebViewChromium implements WebViewProvider
Field field = object.getClass().getDeclaredField("mContentsClientAdapter");
field.setAccessible(true);
object= field.get(object); // object => WebViewContentsClientAdapter
field = object.getClass().getDeclaredField("mWebViewClient");
field.setAccessible(true);
object= field.get(object);
if (object instanceof WebViewClient) { webViewClient = (WebViewClient) object; }
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} finally { return webViewClient; }
}

3、将自己的WebViewClient 和百川的WebViewClient 结合

package com.emar.bcsdk;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient; /**
* Created by ak_star on 2016/6/2.
*/
public class MixBaiCWebViewClient extends WebViewClient {
private WebViewClient mMyselfClient = null; // 自己应用的WebViewClient
private WebViewClient mBaiCClient = null; // 百川WebViewClient public MixBaiCWebViewClient(WebViewClient myself, WebViewClient baiClient) {
mMyselfClient = myself;
mBaiCClient = baiClient;
} @Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
if (mBaiCClient != null) { mBaiCClient.onReceivedError(view, errorCode, description, failingUrl); }
if (mMyselfClient != null) { mMyselfClient.onReceivedError(view, errorCode, description, failingUrl); }
} @Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (mBaiCClient != null) { mBaiCClient.onPageStarted(view, url, favicon); }
if (mMyselfClient != null) { mMyselfClient.onPageStarted(view, url, favicon); }
} @Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (mBaiCClient != null) { mBaiCClient.onPageFinished(view, url); }
if (mMyselfClient != null) { mMyselfClient.onPageFinished(view, url); }
} @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean result = super.shouldOverrideUrlLoading(view, url);
if (mMyselfClient != null)
result = mMyselfClient.shouldOverrideUrlLoading(view, url);
if (mBaiCClient != null) {
if (!result) {
result = mBaiCClient.shouldOverrideUrlLoading(view, url);
} else { mBaiCClient.shouldOverrideUrlLoading(view, url); }
}
return result;
} @TargetApi()
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mBaiCClient != null) {
mBaiCClient.onReceivedSslError(view, handler, error);
} else if (mMyselfClient != null) {
mMyselfClient.onReceivedSslError(view, handler, error);
}
}
}

4、最后重新设置给 WebView

webView.setWebViewClient(new MixBaiCWebViewClient(client, baiCWebViewClient));

上述方案已经经过本人测试,可以实现 淘宝授权免登服务,同时也触发了自己的 WebViewClient 中的方法执行。

但毕竟此方案不是正规途径,有正规方法,还是用正规方法。

注意:1、此方法再升级百川sdk后,要重新检查是否仍然可行

        2、由于使用了反射,android sdk 如果变量名称、类型改变也可能失效,需要重新确定反射对象。  

百川sdk----自己的WebViewClient不被执行【废弃,新版本百川已修复此问题】的更多相关文章

  1. 百川sdk----自己的WebViewClient不被执行

    我在百川sdk的旺旺群中,追问这个问题N多次,一直没有人答复,哎,凡事都要靠自己..... 1.先查看下百川sdk中,是怎么处理咱们传递过去的 WebViewClient public class l ...

  2. 转载 -- Cocoapod方式引入百川SDK -报错[!] Unable to find a specification for `xxx`

    [cocopad集成百川sdk官网] iOS需要填写BundleID .BundleID要是当前应用的BundleID.勾选淘宝登录基础包下载SDK. 注意事项:将下载的SDK中的身份图片yw_122 ...

  3. iOS 阿里百川SDK集成注意点

    百川SDK是阿里系OneSDK的终极版本,里面包含了所有的阿里系的基本所有的SDK,集成的时候你只需要勾选对应的你需要的模块,然后生成对应的SDK即可,百川主要是针对帮助APP开发者在各种场景下快速. ...

  4. 删除ecshop底部共执行个查询Gzip 已禁用,占用内存方法

    删除ecshop底部共执行个查询Gzip 已禁用,占用内存方法 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2013-03-25   “共执行 41 个查询,用时 2 ...

  5. 错误 3 未找到类型“sdk:Label”。请确保不缺少程序集引用并且已生成所有引用的程序集。

    错误: 错误 3 未找到类型“sdk:Label”.请确保不缺少程序集引用并且已生成所有引用的程序集. 错误 1 命名空间“http://schemas.microsoft.com/winfx/200 ...

  6. 对于百川SDK签名验证的问题

    SDK是要在wantu.taobao.com生成的.而生成这个SDK其实是要上传一个apk,而这个上传其实就是取他的签名而已.验证就是那张yw222那张图片.重点是你上传的apk的签名是不是跟你的生成 ...

  7. 阿里百川SDK初始化失败 错误码是203

    由idea换到Androidstudio 了,结果报这个错,之前好好的啊!!! 设置问题:

  8. Fastjson 爆出远程代码执行高危漏洞,更新版本已修复

    fastjson近日曝出代码执行漏洞,恶意用户可利用此漏洞进行远程代码执行,入侵服务器,漏洞评级为“高危”. 基本介绍fastjson 是一个性能很好的 Java 语言实现的 JSON 解析器和生成器 ...

  9. ThinkPHP5远程代码执行高危漏洞(附:升级修复解决方法)

    漏洞描述 由于ThinkPHP5框架对控制器名没有进行足够的安全检测,导致在没有开启强制路由的情况下,黑客构造特定的请求,可直接GetWebShell. 漏洞评级 严重 影响版本 ThinkPHP 5 ...

随机推荐

  1. Hive中数据的导入与导出

    最近在做一个小任务,将一个CDH平台中Hive的部分数据同步到另一个平台中.毕竟我也刚开始工作,在正式开始做之前,首先进行了一段时间的练习,下面的内容就是练习时写的文档中的内容.如果哪里有错误或者疏漏 ...

  2. 【C/C++】C++11 Variadic Templates

    Variadic Templates 1.function template:利用“参数个数逐一递减”的特性,实现递归函数调用 template <typename T, typename... ...

  3. Python cv2库(人脸检测)

    根据访问图片识别 # coding:utf-8 import sysimport math import cv2 # 待检测的图片路径 imagepath = r'l.png' face_cascad ...

  4. shell脚本学习之实例列举

    1.用shell写一个从1加到100的程序: 方法一: #!/bin/bashsum=0for i in {1..100}do   let sum+=$idone   echo $sum 方法二: # ...

  5. freemarker导出word档

    1.word另存为xml:2.xml文件后缀名改成ftl:3.编写完整json字符串备用:4.修改ftl中动态字段为json中对应字段名:5.编写java代码自动生成word文件:(注意:换行用< ...

  6. Oracle中查看SQL语句的索引命中情况及CPU占用

    第一种: 在PL/SQL中,在Explain plan Window中执行要优化的Sql语句.结果,如下图: Object name列中显示了命中的索引名,Cost列显示了CPU的使用率(%). 第二 ...

  7. Archery:开源漏洞评估和管理工具

    Archery:开源漏洞评估和管理工具

  8. winfrom程序文本框第一次选中问题

    想实现这样的功能: 就是在panel中的文本框,当第一次点击文本框时,全选文本框的内容:再次选择时,可以全选,也可以部分选中, 可是文本框总是从左全部选中,还不能从右边选择,在Enter或Down事件 ...

  9. JsonP的实现原理?

    动态创建script标签,通过script标签中的src跨域属性,连接对方接口,并将回调函数通过接口传递给对方,对方服务器在准备好数据后再通过调用回调函数并以传递参数的方式将数据返回来.

  10. Spark在StandAlone模式下提交任务,spark.rpc.message.maxSize太小而出错

    1.错误信息org.apache.spark.SparkException: Job aborted due to stage failure:Serialized task 32:5 was 172 ...