Back

Titanium中打电话(make phone call in Titanium)

发布时间: 2015-03-05 21:43:00

refer to:  http://developer.appcelerator.com/question/27711/calling-a-phone-number#59231, and: , http://stackoverflow.com/questions/4275678/how-to-make-phone-call-using-intent-in-android

在Titanium 中有2种方式, 

1. 仅仅打开拨号盘:(最常见,最友好,也不需要权限)

var the_number = '0123456789';
Ti.Platform.openURL('tel:'+the_number);

2. 直接给用户拨出去:(安卓)

var call = 'tel:' + number;
 
var intent = Ti.Android.createIntent({
        action : Ti.Android.ACTION_CALL,
        data : call
        });
Ti.Android.currentActivity.startActivity(intent);

需要权限:

<android xmlns:android="http://schemas.android.com/apk/res/android">
   <manifest>
         <uses-permission android:name="android.permission.CALL_PHONE" />
  </manifest>
</android>

安卓native code: 

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);

注意: Intent.ACTION_CALL: 直接拨出去。 Intent.ACTION_DIAL: 帮用户输入了号码,但是拨的权力留给用户。

Back