Congrats 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 some functionality to do that. That'll be two steps:
MonkeyPhone able to disconnect an active connection, andSince MonkeyPhone is the object talking to the Twilio Client API, let's add
a disconnect() method there:
public class MonkeyPhone implements Twilio.InitListener
{
private Device device;
private Connection connection;
/* ... other methods ... */
public void disconnect()
{
if (connection != null) {
connection.disconnect();
connection = null;
}
}
/* ... other methods ... */
}
And add code in HelloMonkeyActivity to call this new method when the hangup
button is pressed:
public class HelloMonkeyActivity extends Activity implements View.OnClickListener
{
private MonkeyPhone phone;
/* ... other methods ... */
@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.