我有一个 Android 移动应用程序,我正在尝试在其中构建直接呼叫功能。我已在清单文件中添加了所需的权限请求。但在我尝试拨打电话的函数中,出现错误,显示未解析的引用:CALL_PHONE。
这是我的私人功能:
private fun callPhone(patientTelephone: String?) {
if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this@MainActivity,
arrayOf(Manifest.permission.CALL_PHONE),
REQUESTCALL)
}else {
val intentCall = Intent(
Intent.ACTION_CALL,
Uri.fromParts(
"tel",
patientTelephone,
null
)
)
startActivity(intentCall)
}
}
manifest文件中的权限请求是这样的:
使用权限 android:name="android.permission.CALL_PHONE"
目标SdkVersion 33
将
android.Manifest
导入到您的班级即可解决。