如何在XWalkView中启用javascript?

时间:2015-04-03 21:49:37

标签: crosswalk-runtime

此网址显示如何使用http://zhangwenli.com/blog/2014/08/25/crosswalk-calling-java-methods-with-javascript/

但是,现在删除了getSettings()函数。

现在如何启用Javascript?

1 个答案:

答案 0 :(得分:10)

public class MyActivity extends Activity {
    private XWalkView xWalkWebView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_activity_xml);
        xWalkWebView = (XWalkView)findViewById(R.id.xwalkView);
        xWalkWebView.addJavascriptInterface(new WebAppInterface(), "Android");
        xWalkWebView.load(url_your_want_to_load,null); 
    }

    public class WebAppInterface {
        @org.xwalk.core.JavascriptInterface
        public void callFunction(){
           // Do your Android Stuff here
        }
    }
}

现在在页面中调用函数:

Android.callFunction();