Get Started

Twilio Client for Android Quickstart Tutorial

Hanging Up Calls from your Android Device

Congratulations on making your first audio connection from your Android device to Twilio!

You should have heard a welcome message but as you probably noticed, you had no way to close the connection as the Hangup button doesn't do anything. So, let's add code in MonkeyPhone to hang up ongoing connection.

MonkeyPhone.java
public void disconnect()
{
    if (connection != null) {
        connection.disconnect();
        connection = null;
    }
}

And add code in HelloMonkeyActivity to call this new method when the hangup button is pressed:

HelloMonkeyActivity.java
@Override
public void onClick(View view)
{
    if (view.getId() == R.id.dialButton) {
        phone.connect();
    }  else if (view.getId() == R.id.hangupButton) {
        phone.disconnect();
    }
}

That's everything! Go ahead and make another call. You can now press the hangup button at any time and your connection will close.
Next: Connecting to a TwiML Application »