Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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());
        ...
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
110 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...