自定义Cordova CordovaWebViewClient上的shouldOverrideUrlLoading不再起作用

马可

我有一个自定义类来覆盖CordovaWebViewClient提供的方法shouldOverrideUrlLoading。

    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);
       }

在我升级到最新版本的Cordova(3.6.3)之前,它一直运行良好。现在不再调用函数shouldOverrideUrlLoading,但是在调试代码时,我可以看到在Cordova库(CordovaWebViewClient类)中正在执行相同的函数。

这是我改写Cordova网络客户端的方法:

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);
        }
托德·T

我今天升级到3.6.3后遇到了同样的问题。它查看了Cordova源代码以弄清楚为什么它被破坏了。在某种程度上init,引入了一种新方法,该方法需要从config.xml中读取一堆参数。如果您的代码未调用该方法,则在加载URL时会遇到这种initIfNecessary情况,这将覆盖已设置的所有自定义客户端。

从他们的代码:

private void initIfNecessary() {
    if (pluginManager == null) {
        Log.w(TAG, "CordovaWebView.init() was not called. This will soon be required.");
        // Before the refactor to a two-phase init, the Context needed to implement CordovaInterface. 
        CordovaInterface cdv = (CordovaInterface)getContext();
        if (!Config.isInitialized()) {
            Config.init(cdv.getActivity());
        }
        init(cdv, makeWebViewClient(cdv), makeWebChromeClient(cdv), Config.getPluginEntries(), Config.getWhitelist(), Config.getExternalWhitelist(), Config.getPreferences());
    }
}

makeWebViewClient即使您可能已经设置了自己的客户端,也可以看到被称为。

我用以下方法解决了这个问题:

ConfigXmlParser parser = new ConfigXmlParser();
parser.parse(activity);

CordovaInterface cordova = (CordovaInterface) activity;
init(cordova, new WFWebViewClient(cordova, this), makeWebChromeClient(cordova),
    parser.getPluginEntries(), parser.getInternalWhitelist(), parser.getExternalWhitelist(),
    parser.getPreferences());

并删除了已弃用的Config.init(activity);

希望这可以为您节省一些我今天浪费的时间。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

iOS 15 上的 SwiftUI,自定义 buttonStyle 不再起作用,它在 iOS 14 上运行良好,如何修复?

Cordova 自定义 URL 方案插件不起作用

自定义Jackson HttpMessageConverter在Spring 4.2中不再起作用

自定义Json Guard在开始升级Laravel App后不再起作用

Kendo AutoComplete-自定义行后键盘导航不再起作用

命令在Thunar自定义操作中不再起作用

Ember数据1.0.0 Beta:RESTAdapter端点自定义不再起作用

Windows Azure网站自定义域不再起作用

将自定义按钮添加到屏幕后不再起作用

添加SSL后,自定义TeamSpeak IP不再起作用

离子cordova-plugin-screen-orientation在Ios上不再起作用

iOS上的Cordova App中的Iframe Youtube视频不再起作用

Cordova iOS 应用程序:此处地图的自定义标记图标不起作用

从Rails 4升级到Rails 5后,自定义错误处理不再起作用

升级到0.7.1后,upickle中的自定义作者/阅读器不再起作用

Bootstrap上的HTML自定义字体不起作用

自定义组件上的OverlayTrigger不起作用

自定义 FeatureUnion 不起作用?

自定义命令不起作用

自定义指令不起作用

自定义 ProgressableStreamContent 不起作用

自定义标签不起作用

自定义EmailValidator不起作用

自定义 UICollectionViewFlowLayout 不起作用

自定义表单不起作用

自Angular / Material从5升级到6后,自定义本机日期适配器不再起作用

CSS自定义光标不起作用,浏览器是否不再支持它?

自定义组件不再正确呈现

Rails测试跳过自定义验证或自定义验证不起作用?