Cordova – How to communicate with native Android?

How to pass data from Cordova to native Android?

JS side

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var exec = require('cordova/exec');
exports.checkTemperature = function(photoPath, success, error) {
exec(success, error, 'Temperature', 'checkTemperature', [photoPath]);
};
var exec = require('cordova/exec'); exports.checkTemperature = function(photoPath, success, error) { exec(success, error, 'Temperature', 'checkTemperature', [photoPath]); };
var exec = require('cordova/exec');

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

Android native side

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@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;
}
@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; }
  @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.


*