美文网首页Android 技术问题及技术分享
Android拨打电话的两种实现方法

Android拨打电话的两种实现方法

作者: ChenME | 来源:发表于2017-04-06 10:48 被阅读7569次
  1. 添加拨打电话的权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
  1. 第一种方法
/**
 * 拨打电话(直接拨打电话)
 * @param phoneNum 电话号码
 */
public void callPhone(String phoneNum){
    Intent intent = new Intent(Intent.ACTION_CALL);
    Uri data = Uri.parse("tel:" + phoneNum);
    intent.setData(data);
    startActivity(intent);
}
  1. 第二种方法
/**
 * 拨打电话(跳转到拨号界面,用户手动点击拨打)
 *
 * @param phoneNum 电话号码
 */
public void callPhone(String phoneNum) {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    Uri data = Uri.parse("tel:" + phoneNum);
    intent.setData(data);
    startActivity(intent);
}

相关文章

网友评论

    本文标题:Android拨打电话的两种实现方法

    本文链接:https://www.haomeiwen.com/subject/clwfattx.html