我有下面给定的代码为我提供了一个自我管理的连接服务。但这已停止处理此错误:
java.lang.SecurityException:此用户未启用此 PhoneAccountHandle!
代码:
class CallManager(context: Context) {
val telecomManager: TelecomManager
var phoneAccountHandle: PhoneAccountHandle
var context: Context
init {
telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
this.context = context
val componentName = ComponentName(this.context, ConnService::class.java)
phoneAccountHandle = PhoneAccountHandle(componentName,"com.darkhorse.videocalltest")
}
fun register(){
val phoneAccount = PhoneAccount.builder(phoneAccountHandle,"com.darkhorse.videocalltest")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) .setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER).build()
telecomManager.registerPhoneAccount(phoneAccount)
}
fun incomingCall(caller: String?){
val callInfo = Bundle()
callInfo.putString("from", caller)
telecomManager.addNewIncomingCall(phoneAccountHandle,callInfo)
Log.i("incomingCall", "incomingCall")
}
}
我确信相同的代码之前运行良好。
这个问题没有帮助。