简体   繁体   中英

How to call native android method(function) from javascript in android phongap application, without using webview?

How can I call a native android method(function), from javascript, in an Android phonegap application, without using webview concept.

Any one help me....

Which version of Cordovo supports this process?

We can wrote custom plugin in phonegap that we can call from javascript.

below is the javascript line to call android function

exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]);

add below code in config file

<feature name="<service_name>">
        <param name="android-package" value="<full_name_including_namespace>" />
    </feature>

below is the android class that needs to exptend Cordova Plugin class.

 public class CustomPlugin  extends CordovaPlugin {
    @Override
            public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        }
    }

Refer phonegap docs for custom plugin development

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM