思路
1、获取拨打电话的号码;
2、利用 Intent 调用系统拨打电话;
实践
1、layout布局
<EditText
android:id="@+id/input_tel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号"/>
<Button
android:id="@+id/goto_tel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="拨打电话去"/>
2、java核心代码
String tel = input_tel.getText().toString(); Intent intent = new Intent(); //创建Intent对象
//intent.setAction(Intent.ACTION_DIAL); //设置动作为跳转到拨打电话页面-手动拨打
intent.setAction(Intent.ACTION_CALL); //设置动作为拨打电话-直接拨打 intent.setData(Uri.parse("tel:" + tel)); // 设置要拨打的电话号码 startActivity(intent); //启动Activity
input_tel 是文本输入框(EditText),这段核心代码就写在(Button)点击事件里面
3、AndroidManifest.xml权限设置
<uses-permission android:name="android.permission.CALL_PHONE"/>
源码:https://github.com/iscopy/Blog