How to call native function from cordova 3.x

ε祈祈猫儿з 提交于 2019-11-29 09:01:07

In the .java file

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.init(); // Calling this is necessary to make this work

    appView.addJavascriptInterface(this, "MainActivity");

    super.loadUrl(Config.getStartUrl());

}

In the javascript

window.MainActivity.customFunctionCalled();

This will only work on TargetSDK<17 . An androidManifest.xml targetSDK need to be set < 17. And for TargetSDK >=17 , I guess you'll need to create some custom plugin. I use this process lowering my target SDK for now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!