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

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

java - Accessing appView from Cordova 5.0.0

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...