从 Cordova 5.0.0 访问 appView [英] Accessing appView from Cordova 5.0.0

查看:36
本文介绍了从 Cordova 5.0.0 访问 appView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很难从最新的 Cordova 安卓版 (5.0.0) 访问 appView.

I'm having real trouble to access appView from the latest Cordova version for Android (5.0.0).

例如,假设我想向我的应用程序添加一个 Javascript 界面.在这个版本之前,我曾经写过这行代码:

For example, say I want to add a Javascript interface to my app. Before this version, I used to write this line of code:

super.appView.addJavascriptInterface(new WebAppInterface(this), "jsInterface");

然后是WebAppInterface:

public class WebAppInterface { ... }

现在,它只是不起作用.Cordova 最近有什么改变吗?我真的不知道该怎么办.

Now, it just does not work. Has Cordova changed something recently? I seriously have no idea of what to do.

在这两种情况下(旧版本和新版本),我的主要活动都具有以下结构:

In both cases (previous version and new one), my main activity has this structure:

public class CordovaApp extends CordovaActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.init();
        loadUrl(Config.getStartUrl());
        ...
}

推荐答案

经过几天的寻找解决方案,我终于让应用程序运行起来.

After days looking for a solution, I finally get the app to work.

Cordova 改变了访问 Android webView 的方式.使用 Cordova 5.0.0 和更新版本的开发人员需要将此行添加到他们的主要活动中:

Cordova has changed the way to access Android webView. Developers using Cordova 5.0.0 and newer versions need to add this line to their main activity:

WebView wV = (WebView)appView.getEngine().getView();

然后,像往常一样调用 wV.例如,添加一个 Javascript 接口:

And then, just call wV as usual. For example, to add a Javascript Interface:

wV.addJavascriptInterface(new WebAppInterface(this), "jsInterface");

我希望这个回答能帮助其他对这个新更新感到困惑的人.

I hope this answer will help other people who are confused about this new update.

这篇关于从 Cordova 5.0.0 访问 appView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆