Intent启动拨号盘,实现打电话功能

Intent启动拨号盘,实现打电话功能

权限

清单文件中添加静态权限

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

代码块中添加动态权限

一键拨号权限属于敏感权限 所以需要动态请求一下

requestPermissions(new String[]{
    
    Manifest.permission.CALL_PHONE},999);

代码

/**
* Intent 意图
* 电话拨号器
*/
// 创建意图对象
Intent intent = new Intent();
// 设置动作
intent.setAction(intent.ACTION_CALL);
// s 是你的 手机号码 !!!“tel:” 固定格式必须加
// 设置数据
intent.setData(Uri.parse(“tel:”+s);
// 开启意图
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/Abner_leader/article/details/108746189