您的位置:首页 > 移动开发 > Android开发

android拨打电话二三事

2016-03-14 18:59 441 查看
相信很多人都做过拨打电话功能,拨打电话有两个界面,一个打电话界面,一个是拨号界面,现在给大家实现一下啊

1.添加权限:

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>


2.立即拨打:

//用intent启动拨打电话
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "18211673289");
if (ActivityCompat.checkSelfPermission(ContactActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
//    ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
//   public void onRequestPermissionsResult(int requestCode, String[] permissions,
//                                          int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
this.startActivity(intent);


3.跳转到拨号页面:

//用intent启动拨打电话
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "18211673289");
if (ActivityCompat.checkSelfPermission(ContactActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
//    ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
//   public void onRequestPermissionsResult(int requestCode, String[] permissions,
//                                          int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
this.startActivity(intent);
}


两种方式分别对应两种需求,使用时请参考具体需求,另外上面代码是android6.0动态权限,当设置 targetSdkVersion 23时,就需要这样添加权限。

记:华为手机6.0系统在测试跳转到拨号界面时,需要在华为应用管理里面允许拨打电话权限,不然会没有反应。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: