【问题标题】:How to fix java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user?如何修复 java.lang.SecurityException:此 PhoneAccountHandle 未为此用户启用?
【发布时间】:2021-01-19 15:00:55
【问题描述】:

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

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

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

This question 没有帮助。

【问题讨论】:

标签: android-connectionservice


【解决方案1】:

registerPhoneAccount

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 2022-01-11
    • 2010-12-22
    • 2011-12-30
    • 2021-01-29
    相关资源
    最近更新 更多