Код: Выделить всё
class ConnectionService : android.telecom.ConnectionService() {
override fun onCreateOutgoingConnection(
phoneAccount: PhoneAccountHandle,
request: ConnectionRequest
): Connection {
val connection = VoipConnection()
val extras = request.extras
// Get the user ID we passed in startOutgoingCall
val userId = extras.getString("USER_ID")
val displayName = extras.getString("DISPLAY_NAME")
connection.setInitializing()
connection.setConnectionCapabilities(
Connection.CAPABILITY_MUTE or
Connection.CAPABILITY_SUPPORT_HOLD or
Connection.CAPABILITY_HOLD
)
connection.setAudioModeIsVoip(true)
connection.setCallerDisplayName(displayName, TelecomManager.PRESENTATION_ALLOWED)
connection.setAddress(request.address, TelecomManager.PRESENTATION_ALLOWED)
connection.setActive()
return connection
}
}
class VoipConnection : Connection() {
override fun onStateChanged(state: Int) {
super.onStateChanged(state)
when (state) {
STATE_INITIALIZING -> setInitializing()
STATE_ACTIVE -> setActive()
STATE_HOLDING -> setOnHold()
STATE_DISCONNECTED -> destroy()
}
}
override fun onShowIncomingCallUi() {
super.onShowIncomingCallUi()
setRinging()
}
override fun onAnswer() {
super.onAnswer()
setActive()
}
override fun onReject() {
super.onReject()
setDisconnected(DisconnectCause(DisconnectCause.REJECTED))
destroy()
}
override fun onAbort() {
super.onAbort()
setDisconnected(DisconnectCause(DisconnectCause.CANCELED))
destroy()
}
override fun onDisconnect() {
super.onDisconnect()
setDisconnected(DisconnectCause(DisconnectCause.LOCAL))
destroy()
}
override fun onHold() {
super.onHold()
setOnHold()
}
override fun onUnhold() {
super.onUnhold()
setActive()
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... vice-telec
Мобильная версия