为什么 CordovaWebViewClient 不再在 Cordova 6 中工作

编程入门 行业动态 更新时间:2024-10-23 17:35:58
本文介绍了为什么 CordovaWebViewClient 不再在 Cordova 6 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经编写了自定义 webviewclient 类来覆盖在cordova 3.7 中运行良好的onPageStarted、onPageFinished 等.

I have written custom webviewclient class to override onPageStarted, onPageFinished etc in cordova 3.7 which was working fine.

在以下代码中,我将 www 目录托管到 Web 服务器并从那里交互cordova插件(条形码扫描仪、nfc、蓝牙等).

In following code is I have hosted the www directory to web server and interacting cordova plugins from there (barcodescanner, nfc, bluetooth etc).

public class MainActivity extends CordovaActivity { private WebView webView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.init(); loadUrl("example"); } public class CustomCordovaWebViewClient extends CordovaWebViewClient { public CustomCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) { super(cordova, view); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); Log.i("CSP Log", "onPageStarted: " + url); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); Log.i("CSP Log", "onPageFinished: " + url); } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){ super.doUpdateVisitedHistory(view, url, isReload); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); } } }

一年后,我将项目从cordova 3.7 迁移到cordova 6,但我发现上面的代码已损坏,例如CordovaWebViewClient、super.onPageStarted 等 无法解析符号.我也尝试过 CordovaWebViewImpl 并让自己感到困惑.

After a year, I have migrated project from cordova 3.7 to cordova 6 but I found above code broken like CordovaWebViewClient, super.onPageStarted etc can't resolve symbols. I also tried CordovaWebViewImpl and confused myself.

在谷歌上搜索了很多之后,我找到了大部分在 2011-14 年给出但不适用的解决方案.我找不到对我有帮助的cordova 文档.

After searching alot on google I found solution which were mostly given in 2011-14 which are not applicable. I couldn't found cordova docs helpful.

推荐答案

被SystemWebViewClient

你应该这样做:

SystemWebView wv = (SystemWebView)appView.getView(); wv.setWebViewClient(new SystemWebViewClient((SystemWebViewEngine)appView.getEngine()){ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); Log.i("CSP Log", "onPageStarted: " + url); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); Log.i("CSP Log", "onPageFinished: " + url); } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){ super.doUpdateVisitedHistory(view, url, isReload); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); } });

更多推荐

为什么 CordovaWebViewClient 不再在 Cordova 6 中工作

本文发布于:2023-11-14 13:40:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   CordovaWebViewClient   Cordova

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!