You will need to write a plugin for this functionality. The first thing you will need to do is add the:
android.permission.CALL_PRIVILEGED
to your AndroidManifest.xml. This will allow you to dial a number skipping the Dialer app. A small bit of JavaScript code is required for the plugin interface:
cordova.define("cordova/plugin/emergencydialer",
function(require, exports, module) {
var exec = require("cordova/exec");
var EmergencyDialer = function () {};
var EmergencyDialerError = function(code, message) {
this.code = code || null;
this.message = message || '';
};
EmergencyDialer.CALL_FAILED = 0;
EmergencyDialer.prototype.call = function(telephoneNumber,success,fail) {
exec(success,fail,"EmergencyDialer", "call",[telephoneNumber]);
};
var emergencyDialer = new EmergencyDialer();
module.exports = emergencyDialer;
});
Then you'll need to write some Java code to do the phone call. You'll need to create a new class that extends the Plugin class and write an execute method like this:
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
try {
if (action.equals("call")) {
String number = "tel:" + args.getString(0);
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
this.cordova.getActivity().startActivity(callIntent);
}
else {
status = PluginResult.Status.INVALID_ACTION;
}
return new PluginResult(status, result);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
Whatever you call this class you'll need to add a line in the res/xml/config.xml file so the PluginManager can create it.
<plugin name="EmergencyDialer" value="org.apache.cordova.plugins.EmergencyDialer"/>
and finally in your JavaScript code you'll need to create they plugin and call it like this:
function panicButton() {
var emergencyDialer = cordova.require("cordova/plugin/emergencydialer");
emergencyDialer.call("18005551212");
}
That should about do it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…