Java

Gestionar la llamada

Recibir llamada

Añadir call en la parte superior de MainActivity clase:

Para escuchar las llamadas entrantes añada incoming call listener al final de onCreate método inside MainActivity clase:

La aplicación escuchará ahora el evento de llamada entrante. El código anterior muestra los botones de responder y rechazar llamada cuando se recibe el evento de llamada entrante. Observa que estás almacenando call referencia para interactuar posteriormente con la llamada.

Antes de que puedas realizar acciones usando UI también necesitas añadir listeners a los botones. Añade este código en el onCreate en MainActivity clase:

Para responder a la llamada, añada answerCall método inside MainActivity clase:

Tras responder a la llamada, el end call se mostrará.

NOTA: En SuppressLint se utiliza por simplicidad. En la aplicación de producción debes asegurarte de que se conceden los permisos antes de responder a la llamada.

Para rechazar la llamada añada rejectCall método inside MainActivity clase:

Para finalizar la llamada añada endCall método inside MainActivity clase:

Tenga en cuenta que después de rechazar o finalizar con éxito la llamada se establece call a null.

NOTA: Puede utilizar call.addCallEventListener oyente para ser notificado cuando la persona que llama finaliza la llamada.

Construir y ejecutar

Asegúrese de que el servidor webhook que construyó en los pasos anteriores sigue funcionando.

Pulse el botón Ctrl + R para crear y ejecutar la aplicación. Llama al número.

Llame al número asociado a su solicitud en el paso anterior.

Webhooks

A medida que avanza con la llamada, por favor, cambie al terminal y observe el /voice/answer al que se llama para recuperar la NCCO:

NCCO request: - caller: 447700900000 - callee: 442038297050

Además, a medida que la convocatoria avanza por las distintas fases, /voice/event se envían eventos:

EVENT: { headers: {}, from: '447700900000', to: '442038297050', uuid: '0779a56d002f1c7f47f82ef5fe84ab79', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'ringing', direction: 'inbound', timestamp: '2021-03-29T21:20:05.582Z' } --- EVENT: { headers: {}, from: '447700900000', to: '442038297050', uuid: '0779a56d002f1c7f47f82ef5fe84ab79', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'started', direction: 'inbound', timestamp: '2021-03-29T21:20:05.582Z' } --- EVENT: { start_time: null, headers: {}, rate: null, from: '447700900000', to: '442038297050', uuid: '0779a56d002f1c7f47f82ef5fe84ab79', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'answered', direction: 'inbound', network: null, timestamp: '2021-03-29T21:20:06.182Z' } --- EVENT: { from: '447700900000', to: 'Alice', uuid: '944bf4bf-8dc7-4e23-86b2-2f4234777416', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'started', direction: 'outbound', timestamp: '2021-03-29T21:20:13.025Z' } --- EVENT: { start_time: null, headers: {}, rate: null, from: '447700900000', to: 'Alice', uuid: '944bf4bf-8dc7-4e23-86b2-2f4234777416', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'answered', direction: 'outbound', network: null, timestamp: '2021-03-29T21:20:13.025Z' } --- EVENT: { headers: {}, end_time: '2021-03-29T21:20:16.000Z', uuid: '944bf4bf-8dc7-4e23-86b2-2f4234777416', network: null, duration: '5', start_time: '2021-03-29T21:20:11.000Z', rate: '0.00', price: '0', from: '447700900000', to: 'Alice', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'completed', direction: 'outbound', timestamp: '2021-03-29T21:20:17.574Z' } --- EVENT: { headers: {}, end_time: '2021-03-29T21:20:18.000Z', uuid: '0779a56d002f1c7f47f82ef5fe84ab79', network: 'GB-FIXED', duration: '12', start_time: '2021-03-29T21:20:06.000Z', rate: '0.00720000', price: '0.00144000', from: ' 447700900000', to: '442038297050', conversation_uuid: 'CON-8f5a100c-fbce-4218-8d4b-16341335bcd6', status: 'completed', direction: 'inbound', timestamp: '2021-03-29T21:20:17.514Z' } ---