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.
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.
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();
}
}
});</pre>
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.
Posted from my blog with : https://www.ipragmatech.com/steps-make-call-android-twilio-voice/