Twilio voice: Receive Call On Your Android Mobile

Android Twilio voice

Twilio voice is a telephony web-service API that lets you use your existing web languages and skills to build voice and SMS applications. Twilio is a third-party service. Here we have easy steps to receive call using android twilio voice.

Twilio Voice allows your applications to make and receive phone calls. Twilio SMS allows your applications to make and receive SMS messages. Twilio Client allows your applications to enable voice communication using existing Internet connections, including mobile connections.

Building Apps That Talk in the Cloud

Using Twilio Client for Android, developers have access to a few key features that will make building communications apps easy.

  • Real-time Presence – Build buddy lists into any app letting users know who is online and set up notifications when a user is available for voice chat
  • App Backgrounding – The SDK can receive voice calls even when a different app is in use, letting users switch between apps easily to respond to incoming calls.
  • Cross-Platform Interoperability – Twilio Client supports Android, iOS, and web browsers so apps can make calls between any platform, including bridging VoIP calls with traditional phone calls.
  • Voice Over Data and WiFi connections – Make and receive calls over data and WiFi connections without using carrier minutes.

Steps to make call in android Twilio voice

Step 1: Configure your application to use twilio libraries

import com.twilio.client.Connection;
import com.twilio.client.ConnectionListener;
import com.twilio.client.Device;
import com.twilio.client.DeviceListener;
import com.twilio.client.PresenceEvent;
import com.twilio.client.Twilio;
private static final String TOKEN_SERVICE_URL = "your twilio url";

Step 2: Initilizze the twilio sdk

if (!Twilio.isInitialized()) {
    Twilio.initialize(getApplicationContext(), new Twilio.InitListener() {

        /*
         * Now that the SDK is initialized we can register using a Capability Token.
         * A Capability Token is a JSON Web Token (JWT) that specifies how an associated Device
         * can interact with Twilio services.
         */
        @Override
        public void onInitialized() {
            Twilio.setLogLevel(Log.DEBUG);
            /*
             * Retrieve the Capability Token from your own web server
             */
            retrieveCapabilityToken(clientProfile);
        }

        @Override
        public void onError(Exception e) {
            Log.e(TAG, e.toString());
            Toast.makeText(ClientActivity.this, "Failed to initialize the Twilio Client SDK", Toast.LENGTH_LONG).show();
        }
    });
}

Step 3: In this step generate Capability tokens. Capability tokens allow you to add Twilio capabilities to web and mobile applications without exposing your super secret Auth Token in JavaScript or any other client-side environment.

  • Your server provides a Capability Token to each client.
  • Each token contains specific information that enables Twilio to identify that the client belongs to your Twilio account, and what permissions (‘capabilities’) you have granted this user.
Uri.Builder b = Uri.parse(TOKEN_SERVICE_URL).buildUpon();
if (newClientProfile.isAllowOutgoing()) {
    b.appendQueryParameter("allowOutgoing", newClientProfile.allowOutgoing ? "true" : "false");
}
if (newClientProfile.isAllowIncoming() && newClientProfile.getName() != null) {
    b.appendQueryParameter("client", newClientProfile.getName());
}

Ion.with(getApplicationContext())
        .load(b.toString())
        .asString()
        .setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String capabilityToken) {
                if (e == null) {
                    Log.d(TAG, capabilityToken);

                    // Update the current Client Profile to represent current properties
                    ClientActivity.this.clientProfile = newClientProfile;

                    // Create a Device with the Capability Token
                    createDevice(capabilityToken);
                } else {
                    Log.e(TAG, "Error retrieving token: " + e.toString());
                    Toast.makeText(ClientActivity.this, "Error retrieving token", Toast.LENGTH_SHORT).show();
                }
            }
        });

Making an HTTP request to the /token endpoint of the web-server returns a Capability Token, which, when provided to a Device constructor, grants the new Device capabilities such as making outgoing calls or allowing incoming calls.

Conclusion

If you want to implement android twilio voice call in your project then you will find these steps more easy. Implementation of android twilio voice has very easy steps as described above. You can edit the xml and activity files in your own way to make it more attractive as per your requirements.

Go to Call android using twilio voice Example on Github

Refrences

Twilio : Twilio documentation that gives the information about twilio.

Android : Android document that gives the information about android that is useful for developer.

Twilio voice: Receive Call On Your Android Mobile was last modified: November 19th, 2016 by Narendra Nagpal