我有一个自定义类来覆盖由CordovaWebViewClient提供的方法shouldOverrideUrlLoading。shouldOverrideUrl加载自定义科尔多瓦CordovaWebViewClient不工作了
public class CordovaCustomWebClient extends CordovaWebViewClient {
public CordovaCustomWebClient(CordovaInterface cordova, CordovaWebView view) {
super(cordova, view);
}
@SuppressLint("DefaultLocale")
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
EventLogger.logMessage(getClass(), "--------------- shouldOverrideUrlLoading ---------------");
return super.shouldOverrideUrlLoading(view, url);
}
这是工作的罚款,直到我已经升级到科尔多瓦的最新版本(3.6.3)。现在,函数shouldOverrideUrlLoading不再被调用,但是当我调试代码时,我可以看到在Cordova库(类CordovaWebViewClient)中执行的相同函数。
这是我做的重写科尔多瓦的Web客户端:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_application);
cordovaWebView = (CordovaWebView) this.findViewById(R.id.mainView);
Config.init(this);
Application application = null;
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
application = (Application) bundle.get("key_application");
}
// Local Url to load application
String url = "";
if (application != null) {
if (HubManagerHelper.getInstance().getApplicationHosted() == null) {
MyApp app = (MyApp) getApplication();
app.registerDefaultHubApplication();
}
url = String.format(WebServicesClient.URL_WEB_APPLICATION, HubManagerHelper.getInstance()
.getApplicationHosted(), application.getPath());
}
cordovaWebView.setWebViewClient(new CordovaCustomWebClient(this, cordovaWebView));
// Listener to Download Web File with Native Component - Download Manager
cordovaWebView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
long contentLength) {
downloadAndOpenFile(WebApplicationActivity.this, url);
}
});
String ua = cordovaWebView.getSettings().getUserAgentString();
String appVersion = getAppVersion();
String newUA = ua.concat(" MyApp." + appVersion);
cordovaWebView.getSettings().setUserAgentString(newUA);
if (savedInstanceState == null) {
cordovaWebView.loadUrl(url);
} else {
((LinearLayout) findViewById(R.id.view_loading)).setVisibility(View.GONE);
}
谢谢托德!我其实做了一些不同的事情,但问题恰恰在于那个。我创建了自己的自定义方法makeWebViewClient,它检查是否已经有一个,如果是的话,它不会取代它。在我的情况下解决它。 @Override 公共CordovaWebViewClient makeWebViewClient(CordovaInterface科尔多瓦){ \t如果(this.webViewClient == NULL) \t { \t \t webViewClient = super.makeWebViewClient(科尔多瓦); \t} \t回报this.webViewClient; } – Marco 2014-10-06 10:41:39
我实际上更喜欢你的解决方案,并且几乎重构了我的方法来覆盖'makeWebViewClient',但initIfNecessary中有关初始化的注释很快就让我不敢回想起进行不必要的复杂init调用。我不知道为什么我们不得不自己配置解析。 – 2014-10-06 13:21:32
@ToddT你能否详细说明你把你的代码块放在哪里? – mentat 2014-10-29 08:58:01