4

通话中服务

我正在使用InCallService来监听来电,并且在onCallStateChanged回调中正在更新通话状态,我已经成功实现了直到保持“通话 1”并连接“通话 2”,所以“通话 1”处于HOLD状态,“通话 2”处于活动状态状态分别,现在当我点击合并时,它会抛出一个错误

“无法合并通话”

我正在使用会议方法来合并通话

为了更好地理解,我在下面发布我的代码

 class CallService : InCallService() {

    override fun onCallAdded(call: Call) {
        super.onCallAdded(call)
        CallManager.updateCall(call)

    }

    private val callCallback = object : Call.Callback() {
        override fun onStateChanged(call: Call, state: Int) {
            CallManager.updateCall(call)
        }
    }

    override fun onCallRemoved(call: Call) {
        super.onCallRemoved(call)
        call.unregisterCallback(callCallback)
        CallManager.updateCall(null)
    }
}


@TargetApi(Build.VERSION_CODES.M)
object CallManager {
    private const val LOG_TAG = "CallManager"
    private val subject = BehaviorSubject.create<GsmCall>()
    private var currentCall: Call? = null
    private var anotherCall: Call? = null
    fun updates(): Observable<GsmCall> = subject


    fun updateCall(call: Call?) {
        if (currentCall != null) {
            call?.let {
                if (it.details.handle.schemeSpecificPart ==
                    currentCall!!.details.handle.schemeSpecificPart
                )
                    currentCall = call
                else anotherCall = call
            }
        } else currentCall = call
        call?.let {
            subject.onNext(it.toGsmCall())
        }
    }


    fun cancelCall() {
        currentCall?.let {
            when (it.state) {
                Call.STATE_RINGING -> rejectCall()
                else -> disconnectCall()
            }
        }
    }


    fun holdCall() {
        currentCall?.let {
            when (it.state) {
                Call.STATE_ACTIVE -> currentCall?.hold()
                else -> Log.i(LOG_TAG, "Call not in connected state")
            }
        }
    }

//Conference call method
    fun conferenceCall() {
        anotherCall?.conference(currentCall)
    }

    fun swapConferenceCall() {
        currentCall?.swapConference()
    }

    fun mergeConferenceCall() {
        currentCall?.mergeConference()
    }

    fun unHoldCall() {
        currentCall?.let {
            when (it.state) {
                Call.STATE_HOLDING -> currentCall?.unhold()
                else -> Log.i(LOG_TAG, "Call not in connected state")
            }
        }
    }

    fun isCallOnHold(): Boolean {
        currentCall?.let {

            return when (it.state) {
                Call.STATE_HOLDING -> true
                else -> false
            }
        }
        return false
    }

    fun acceptCall() {
        Log.i(LOG_TAG, "acceptCall")
        currentCall?.let {
            it.answer(it.details.videoState)
        }
    }

    private fun rejectCall() {
        Log.i(LOG_TAG, "rejectCall")
        currentCall?.reject(false, "")
    }

    private fun disconnectCall() {
        Log.i(LOG_TAG, "disconnectCall")
        currentCall?.disconnect()
    }

}
4

0 回答 0