How to fix java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user?

Viewed 662

I had the below given code working for me to make a self managed connecion service. But this has stopped working with this error:

java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user!

Code:

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

I am sure the same code was working fine earlier.

This question doesn't help.

1 Answers

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

Enable PhoneAccount

Intent intent=new Intent();
        intent.setClassName("com.android.server.telecom","com.android.server.telecom.settings.EnableAccountPreferenceActivity");
        startActivity(intent);
Related