方式一:直接呼叫
需要权限<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,否则在某些手机上发生异常无法跳转
本文介绍了在Android应用中实现电话调用的两种方法。第一种是直接呼叫,需要使用CALL_PHONE权限,在API 23及以上的设备上需动态申请。第二种是跳转至拨号页面,无需特殊权限。文章提供了具体的Intent代码示例。
1749

被折叠的 条评论
为什么被折叠?



