1、要使用Android系统中的电话拨号功能,首先必须在AndroidManifest.xml功能清单中加入允许拨打电话的权限:
<uses-permission android:name="android.permission.CALL_PHONE" /> // 允许拨打电话权限
2、进行拨打电话的代码:
a、调用Android系统的拨号界面,但不发起呼叫,用户按下拨号键才会进行呼叫
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button callBut = (Button)findViewById(R.id.callBut);
- callBut.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- 黄色必须有
- Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:13800138000"));
- startActivity(intent);
- }
- });
- }
b、直接拨号发起呼叫
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button callBut = (Button)findViewById(R.id.callBut);
- callBut.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://13800138000"));
- startActivity(intent);
- }
- });
- }