javascript 通过单击 ionic 应用程序上的按钮发起呼叫

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32413505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:14:04  来源:igfitidea点击:

initiate a call by clicking button on ionic app

javascriptangularjscordovaionic

提问by Himanshu Khandelwal

i was using a href="tel:+1-1800-555-5555 " Call me" to call , but it is not initiating the call directly rather than putting the number in the box / asking for confirmation ..can i call directly , as if we click "Call Me" and the call gets started, i am using ionic + angular do i have to include cordova , have checked this articale but not much help:

我正在使用 href="tel:+1-1800-555-5555 "Call me" 打电话,但它不是直接发起呼叫,而是将号码放入框中/要求确认..我可以直接打电话吗,就好像我们单击“呼叫我”并开始呼叫一样,我正在使用 ionic + angular 是否必须包含 cordova ,已检查此文章但没有太大帮助:

http://rickluna.com/wp/2012/02/making-a-phone-call-from-within-phonegap-in-android-and-ios/

http://rickluna.com/wp/2012/02/making-a-phone-call-from-within-phonegap-in-android-and-ios/

回答by Mudasser Ajaz

Using a href="tel:+1-1800-555-5555 " will not work as you want, add this pluginto your project by running command
cordova plugin add https://github.com/Rohfosho/CordovaCallNumberPlugin.git

使用 href="tel:+1-1800-555-5555 " 将无法正常工作,请通过运行命令将此插件添加到您的项目中
cordova plugin add https://github.com/Rohfosho/CordovaCallNumberPlugin.git

and in your project use this line to make call

并在您的项目中使用此行拨打电话

window.plugins.CallNumber.callNumber(onSuccess, onError, number);


onSuccessand onErrorare callback functions, so declare them also.
Note: If you have skype installed, it will ask you to either make call from skype or direct phone. Otherwise it will directly start call.


onSuccessonError是回调函数,所以也声明它们。
注意:如果您安装了 Skype,它会要求您从 Skype 或直拨电话拨打电话。否则它会直接开始调用。

Full JS Code:

完整的 JS 代码:

 $scope.CallNumber = function(){ 
    var number = '18002005555' ; 
    window.plugins.CallNumber.callNumber(function(){
     //success logic goes here
    }, function(){
     //error logic goes here
    }, number) 
  };

回答by Justin Tran

You need to put this in your config.xmlfile for the href tel:phonenumberto work

你需要把它放在你的config.xml文件中href tel:phonenumber才能工作

<access origin="tel:*" launch-external="yes" />