Cordova – How to communicate with native Android?

How to pass data from Cordova to native Android?

JS side

var exec = require('cordova/exec');

exports.checkTemperature = function(photoPath, success, error) {
    exec(success, error, 'Temperature', 'checkTemperature', [photoPath]);
};

Android native side

  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;

    if (action.equals("checkTemperature")) {
      String photoPath = args.getString(0);
      ...
      return true;
    }

    return false;
  }

Be the first to comment

Leave a Reply

Your email address will not be published.


*