您需要添加運行時權限。 Download the source code from here
//點擊佈局的功能:
rl_call.setOnClickListener {
if (boolean_call) {
phonecall()
}else {
fn_permission(Manifest.permission.CALL_PHONE,CALLMODE)
}
}
//請求許可
fun fn_permission(permission:String,mode:Int){
requestPermissions(permission, object : PermissionCallBack {
override fun permissionGranted() {
super.permissionGranted()
Log.v("Call permissions", "Granted")
boolean_call=true
phonecall()
}
override fun permissionDenied() {
super.permissionDenied()
Log.v("Call permissions", "Denied")
boolean_call=false
}
})
}
//函數調用的意圖
fun phonecall() {
val intent = Intent(Intent.ACTION_CALL);
intent.data = Uri.parse("tel:1234567890s")
startActivity(intent)
}
謝謝!
也許這有助於:https://developer.android.com/training/permissions/requesting.html?hl=zh-CN 419 –
[android請求運行時權限調用操作](https:// stackoverflow。 com/questions/42057040/android-request-runtime-permission-to-call-action) – jrtapsell
爲什麼只有標籤kotlin?最後添加android。而你的問題是重複[請求權限](https://stackoverflow.com/questions/42057040/android-request-runtime-permission-to-call-action) – kurt