Using Android SDK

This guide provides you to make the simplest application to make audio calls. You can download/clone the application example using the following link: Demo project.

Android SDK has two dependencies: okhttp and gson. It also applies to the compat-versions which appeared since version 2.2.0. You can check the levels of dependencies according to the Android SDK version directly in the Maven. Note that there could be a delay between the last release and appearance in Maven’s searching index.

Adding SDK to your application

  • IMPORTANT: If you use version before 2.1.2, please remove all .jar, .so and .aar files from your project
  • Modify build.gradle file that is located at the root level of your project to add mavenCentral() to repositories list:
    1. allprojects {
    2. repositories {
    3. jcenter()
    4. mavenCentral() //add this line
    5. }
    6. }
  • Edit build.gradle and add voximplant-sdk as compile files target in dependencies section. Paste the actual version from the changelog:
    1. dependencies {
    2. ...
    3. compile 'com.voximplant:voximplant-sdk:2.3.0' //Paste the actual version from the changelog
    4. }

Initializing SDK

Your application will require following permissions. They will be automatically merged to AndroidManifest by adding Android SDK as compile dependencies. You can also set them manually if you are using different build system.

  1. <uses-permission android:name="android.permission.BLUETOOTH" />
  2. <uses-permission android:name="android.permission.CAMERA"/>
  3. <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
  4. <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
  5. <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  6. <uses-permission android:name="android.permission.INTERNET"/>
  7. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  8. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Bear in mind that CAMERA and RECORD_AUDIO permissions need to be prompted to a user since Android 6.0 (use the Voximplant.getMissingPermissions method to see the permissions that are not granted by the user).

Create the new singletone of type IClient and initialize it as specified in documentation:

IClient client = Voximplant.getClientInstance(Executors.newSingleThreadExecutor(), getApplicationContext(), new ClientConfig());

Logging in

Then you need to connect to the cloud and authorize the user. The IClient.connect (it is similar to WEB SDK initialization) and IClient.login methods handle with it. You also have to set the appropriate listeners to handle with the connection and authentication results: IClientSessionListener and IClientLoginListener. For example, you can connect to the cloud and login user myuser to application myapp in your VoxImplant account named myaccount with password mypass:

  1. public class SomeClass implements IClientSessionListener, IClientLoginListener {
  2. private IClient client;
  3.  
  4. // ctor and other logic here
  5. // Note: you also need to implement other methods from
  6. // IClientLoginListener and IClientSessionListener
  7.  
  8. @Override
  9. public void onConnectionEstablished() {
  10. Log.i(TAG, "Connection established");
  11. //For other login methods please see the article:
  12. // https://voximplant.com/blog/using-tokens-to-avoid-password-save
  13. client.login("myuser@myapp.myaccount.voximplant.com", "mypass");
  14. }
  15.  
  16. @Override
  17. public void onLoginSuccessful(String displayName, AuthParams authParams) {
  18. Log.i(TAG, "Login succeeded");
  19. }
  20.  
  21. public void connectToVoximplant() {
  22. client.connect();
  23. client.setClientSessionListener(this);
  24. client.setClientLoginListener(this);
  25. }
  26. }

Making calls

Use IClient.callTo and ICall.start methods to initiate an outgoing call. To inspect the call conditions you have to be able to catch call events - for this purpose set the ICallListener via ICall.addCallListener.

  1. boolean isVideo = false;
  2. String customData = null;
  3. VideoFlags videoFlags = new VideoFlags(false, false); //disable video for audio calls
  4. ICall call = client.callTo(clientNumber, videoFlags, customData);
  5. Map<String, String> headers = null;
  6. call.start(headers);

Receiving calls

You have to set listener IClientIncomingCallListener to handle with an Incoming call. When an application receives an incoming call, onIncomingCall method is called. Use the ICall.answer method to answer a call:

  1. public void onIncomingCall(ICall call, boolean hasIncomingVideo, Map<String, String> headers) {
  2. String customData = null;
  3. Map<String, String> headers = null;
  4. call.answer(customData, new VideoFlags(hasIncomingVideo, hasIncomingVideo), headers);
  5. }

Terminating calls

Using the ICall.hangup method allows to terminate the call properly. Both participants will receive the ICallListener.onCallDisconnected event after hangup's call will be executed.

  1. Map<String, String> headers = null;
  2. call.hangup(headers);
  3.  



For more information, please read our reference documentation.