Get Started

Twilio Client SDK for Android Quickstart

Set Up Your Twilio 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 these lines in your PHP file:

$appSid = "APabe7650f654fc34655fc81ae71caa3ff";
// ...
$capability->allowClientOutgoing($appSid, array(), $clientName);

This creates a capability token that tells your device which Twilio Application it will connect to. 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 familar with TwiML, we suggest you head over to the Twilio Markup Language Quickstart.

So the string starting with 'AP' is an Application SID. The default one above is a demo app created by Twilio that serves up a very simple TwiML document that uses <Say> to read a greeting.

In this section, we'll:

  1. Write our own TwiML to change what happens when you dial,
  2. Create a Twilio Application, and
  3. Instruct our PHP script to use this new application

Let's build a simple application in PHP to serve TwiML from your web host. Create a new file called hello-client-monkey-twiml.php on your server and copy-paste the following code into that file:

header('Content-type: text/xml');
    <Say>Welcome to Twilio Client!</Say>

Assuming your web server is at, try loading up your new PHP script ( in your browser. All set?

Now we're ready to create the new application in your Account Dashboard, so let's navigate to the tab 'DEV TOOLS' and the sub-tab 'TWIML APPS'. This is where you can see all your current Twilio Applications and create new ones. Select 'Add Application' and complete the form with the following information:

  • Name - the name of your application. Choose whatever you want.
  • Description - just something that describes your application a little better.
  • Voice Url - points to your web host serving some TwiML. In our case, it should point to the PHP file we created above:

Click SAVE to create your app. Now, copy the newly created Application SID and paste it into the token generation code at the top of the client script we created before:


// Found in the 'helper-libs' folder, or download twilio-php from
require "Services/Twilio/Capability.php";

$authToken = "secret";

// The app outgoing connections will use:

// The client name for incoming connections:
$clientName = "monkey"; 

$capability = new Services_Twilio_Capability($accountSid, $authToken);

// This allows incoming connections as $clientName: 

// This allows outgoing connections to $appSid with the "From" 
// parameter being the value of $clientName 
$capability->allowClientOutgoing($appSid, array(), $clientName);

// This returns a token to use with Twilio based on 
// the account and capabilities defined above 
$token = $capability->generateToken();

echo $token;

If you restart your Android app (this will cause a new Capability Token to be fetched which will point to your new Twilio app) and press the Dial button again, you should now be hearing your very own welcome message.

Sweet. Now, what if you want to pass variables from your Android app to the script running on the server?

Next: Passing Parameters to Your Application »