从科尔多瓦5.0.0访问appView [英] Accessing appView from Cordova 5.0.0

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

问题描述

我有真正的麻烦访问 appView 从最新科尔多瓦版本为Android(5.0.0)。

举例来说,假设我想补充的JavaScript接口我的应用程序。这个版本之前,我以前写这行code:

  super.appView.addJavascriptInterface(新WebAppInterface(本),jsInterface);
 

然后在 WebAppInterface

 公共类WebAppInterface {...}
 

现在,这是行不通的。拥有科尔多瓦改变了一些东西最近还好吗?我严重不知道该怎么做。

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

 公共类CordovaApp扩展CordovaActivity {
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        super.init();
        使用loadURL(Config.getStartUrl());
        ...
}
 

解决方案

在天寻找一个解决方案,我终于得到了应用程序的工作。

科尔多瓦已经改变访问Android的 web视图的方式。用科尔多瓦5.0.0及更高版本的开发人员需要这行加入到他们的主要活动:

 的WebView WV =(web视图)appView.getEngine()getView()。
 

然后,只需拨打WV如常。例如,要添加的JavaScript接口:

  wV.addJavascriptInterface(新WebAppInterface(本),jsInterface);
 

我希望这个答案将帮助其他人谁是混淆了这个新的更新。

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

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

And then the WebAppInterface:

public class WebAppInterface { ... }

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

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.

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

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