方式一:
首先在AndroidManifest.xml主配置中添加权限
<uses-permission android:name="android.permission.CALL_PHONE" />
直接拨打电话,需要判断是否授权
//判断权限是否打开 没有配置权限则直接返回
Intent intent = null;
Uri uri = Uri.parse("tel:" + phoneNum);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, "请到设置中打开电话权限", Toast.LENGTH_SHORT); intent = new Intent(Settings.ACTION_SETTINGS); context.startActivity(intent); return; }
intent = new Intent(Intent.ACTION_CALL);
intent.setData(uri);
context.startActivity(intent);
方式二:
跳转到拨号界面,用户手动点击拨打
Uri uri = Uri.parse("tel:" + phoneNum);
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(uri);
context.startActivity(intent);