方式一:直接呼叫
需要权限<uses-permission android:name="android.permission.CALL_PHONE" />,6.0及以上系统需要动态申请
val intent = Intent(Intent.ACTION_CALL)
intent.data = Uri.parse("tel:$phone")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
方式二:跳转至拨号页面
无需权限即可
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:$phone")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
注意:这里要添加intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK,否则在某些手机上发生异常无法跳转