2

我有下面给定的代码为我提供了一个自我管理的连接服务。但这已停止处理此错误:

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")
}
}

我确信相同的代码之前运行良好。

这个问题没有帮助。

4

1 回答 1

0

注册电话帐户

PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new    ComponentName(getApplicationContext().getPackageName(),MyConnectionService.class.getName()),"TestApp");
            TelecomManager  telecomManager = (TelecomManager) getApplicationContext().getSystemService(Context.TELECOM_SERVICE);
               PhoneAccount.Builder builder = new PhoneAccount.Builder(phoneAccountHandle, "TestApp");
               builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER);
               PhoneAccount phoneAccount = builder.build();
               telecomManager.registerPhoneAccount(phoneAccount);

启用电话帐户

Intent intent=new Intent();
        intent.setClassName("com.android.server.telecom","com.android.server.telecom.settings.EnableAccountPreferenceActivity");
        startActivity(intent);
于 2021-11-18T09:38:08.833 回答