使用 Connection 服务添加新传入呼叫时如何显示自定义 UI?

问题描述 投票:0回答:0

我正在尝试实现 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)
        
    }

我知道要提供自定义 UI,我需要设置它

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。

onShowIncomingCallUi

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

android android-studio android-service android-connectionservice telecom-manager
© www.soinside.com 2019 - 2024. All rights reserved.