android 如何在使用Connection服务添加NewIncomingCall时显示自定义UI?

w6mmgewl  于 2023-05-12  发布在  Android
关注(0)|答案(1)|浏览(153)

我正在尝试实现ConnectionService。当我添加新的来电时,我会得到系统UI来接收或拒绝呼叫。

var handle = account.accountHandle
        val extras = Bundle()
        extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle)
        val manager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager

        manager.addNewIncomingCall(handle, extras)

我这样注册账号

fun registerConnectionService() {
        val manager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
        val connectionServiceId = getConnectionServiceId()
        val componentName =
            ComponentName(applicationContext, PhoneConnectionService::class.java)
        val phoneAccountHandle = PhoneAccountHandle(componentName, connectionServiceId)
            val builder = PhoneAccount.builder(
                phoneAccountHandle,
                this.resources.getText(R.string.app_name)
            )
            val uri = Uri.fromParts("tel", "123456789", null)
            builder.setSubscriptionAddress(uri)
            builder.setAddress(uri)
            builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)

            builder.setShortDescription("Short description")
            phoneAccount = builder.build()
            manager.registerPhoneAccount(phoneAccount)
        
    }

我知道,给予自定义用户界面,我需要设置这个

builder.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)

接收呼叫时的ConnectionService代码

@Override
    public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
        final CallConnection connection = new CallConnection(this);

        Bundle extras = new Bundle();

        connection.setAddress(request.getAddress(), PRESENTATION_ALLOWED);
        connection.setVideoState(VideoProfile.STATE_AUDIO_ONLY);
        connection.setExtras(extras);
        connection.setConnectionCapabilities(Connection.CAPABILITY_SUPPORT_DEFLECT);
        connection.setRingbackRequested(true);
        connection.setRinging();

        return connection;
    }

但是这个方法仍然没有在我的CallConnection类中被调用,它扩展了Connection。
on显示来电Ui

任何解决方案如何使用ConnectionSerivice实现自定义UI?

nkcskrwz

nkcskrwz1#

我找到解决办法了。
其实我是在做这个。(即设置连接功能)
connection.setConnectionCapabilities(Connection.CAPABILITY_SUPPORT_DEFLECT);
我将其替换为(即设置连接属性)
connection.setconnectionProperties(Connection.PROPERTY_SELF_MANAGED);
并且它开始调用onShowIncomingCallUi。

相关问题