该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//判断Android版本是否大于23
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val checkCallPhonePermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE)
if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CALL_PHONE),
11)
return@OnClickListener
}
}
callDialog(phoneNumber)
private fun callDialog(phoneNumber: String) {
AlertDialog.Builder(activity).setTitle("拨打电话")
.setMessage(phoneNumber + "\n是否立即拨打?")
.setPositiveButton("确认", DialogInterface.OnClickListener { _, _ ->
val intent = Intent(Intent.ACTION_CALL)
val data = Uri.parse("tel:" + phoneNumber)
intent.data = data
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
})
.setNegativeButton("取消", null)
.create().show()
}