End a call
The call can be ended by one of two parties:
- application by the calling the
hangupmethod on thecallinstance - callee by hanging up on the physical device
End call when callee hangups
To end the call (hangup) you need to store the reference to the ongoing call object. Add onGoingCall property at the top of the MainActivity:
You need to store ongoing call reference in the onGoingCall property and add addCallEventListener to notify you when the call ends. In the MainActivity update the body of the startCall method. Please make sure to replace PHONE_NUMBER below with the actual phone number you want to call, in the E.164 format (for example, 447700900000):
When the call is ended (regardless of who ends the call app or callee) the UI is updated to reflect the current call state (make a call button is shown and END CALL button is hidden).
End call in the application
In the MainActivity fill the body of the hangup method:
Notice that after successful hangup you set the value of the onGoingCall property back to null.
Build and Run
Press the Ctrl + R keys to build and run the app. Start and end the call to see the UI changes.
Making an in-app voice call
You make a voice call from an Android app to a phone.