自动调用predefined号码在Android上使用的PhoneGap [英] Call predefined number automatically on Android with PhoneGap

查看:142
本文介绍了自动调用predefined号码在Android上使用的PhoneGap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用的PhoneGap和jQuery,在我的应用程序,我有一个紧急按钮的应用程序,的onclick它会自动调用predefined数量。我设法打开了原生的Andr​​oid拨号器,但我仍需要用户再次点击发送键拨号。

I am writing an app using PhoneGap and Jquery, in my app i have a panic button, onclick it should automatically call a predefined number. I'm managing to open the native android dialer but still i need the user to click again on send button to dial.

我如何可以从应用程序直接调用?

How can i make a direct call from the app?

谢谢!

推荐答案

您需要<一个href="http://docs.phonegap.com/en/2.2.0/guide_plugin-development_index.md.html#Plugin%20Development%20Guide"相对=nofollow>编写插件此功能。你需要做的第一件事是添加:

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

你的Andr​​oidManifest.xml中。这将允许您拨打号码跳过拨号器应用程序。 JavaScript的code小位是必需的插件接口:

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;
});

然后,你需要编写一些Java code做了电话。你需要创建一个扩展插件类的新类,写一个执行的方法是这样的:

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);
    }
}

无论你怎么称呼这个类,你需要添加在res / XML / config.xml文件中的行,以便在插件管理可以创造它。

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"/>

终于在你的JavaScript code,你需要创建自己的插件,并调用它是这样的:

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");
}

这应约做到这一点。

这篇关于自动调用predefined号码在Android上使用的PhoneGap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆