Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need to <a href="http://docs.phonegap.com/en/2.2.0/guide_plugin-development_index.md.html#Plugin%20Development%20Guide" rel="nofollow">write a plugin</a> for this functionality. The first thing you will need to do is add the:</p> <pre><code>android.permission.CALL_PRIVILEGED </code></pre> <p>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:</p> <pre><code>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; }); </code></pre> <p>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:</p> <pre><code>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); } } </code></pre> <p>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.</p> <pre><code>&lt;plugin name="EmergencyDialer" value="org.apache.cordova.plugins.EmergencyDialer"/&gt; </code></pre> <p>and finally in your JavaScript code you'll need to create they plugin and call it like this:</p> <pre><code>function panicButton() { var emergencyDialer = cordova.require("cordova/plugin/emergencydialer"); emergencyDialer.call("18005551212"); } </code></pre> <p>That should about do it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload