Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Android Quickstart: Connecting to a TwiML Application

Wondering what actually happens when you connect using your app, and why you keep hearing that same welcome message? The key to this mystery is in the python server we deployed earlier. Let's take a look at that code:


# some code ommitted

def token():
  account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
  auth_token = os.environ.get("AUTH_TOKEN", AUTH_TOKEN)
  app_sid = os.environ.get("APP_SID", APP_SID)

   capability = TwilioCapability(account_sid, auth_token)

  # This allows outgoing connections to TwiML application
  if request.values.get('allowOutgoing') != 'false':

  # This allows incoming connections to client (if specified)
  client = request.values.get('client')
  if client != None:

  # This returns a token to use with Twilio based on the account and capabilities defined above
  return capability.generate()

This portion of the code is responsible for creating a capability token that tells your Twilio Device what actions it is allowed to perform.

The two lines below tell your device to make outgoing connections to the App Sid APa4983020a0b29fb5db1b1dc68e322fbe.

APP_SID = 'APa4983020a0b29fb5db1b1dc68e322fbe'

# ...


Applications are just references to TwiML URLs that are fetched when a connection is established from a device, a browser, or a phone. If you are not familiar with TwiML, you may want to check out the Twilio Markup Language Quickstart.

The string starting with 'AP' is an Application SID. You entered this Application Sid when you deployed the server in the steps above. That Application's Voice URL points to your server's / endpoint, which returns the TwiML to say "Welcome to Twilio".

<?xml version="1.0" encoding="UTF-8"?>
    <Say>Welcome to Twilio</Say>

We change the user's audio experience by generating different TwiML. Let's continue with an example that lets us dial any phone number.

Next: Passing Parameters to your Application »

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.