Android SDK

anchorFeatures
anchor
  • Audio and/or video 1:1 calling
  • Group space calling
  • Dial by email, Webex Teams User ID, or SIP address
  • Call and event controls, including DTMF
  • Audio and video call control
  • View content and video simultaneously
  • Maximum bandwidth controls
  • Create Teams, Spaces, Memberships, and Messages
  • Receive and share content
  • Message securely
  • Group call with multistream view new
anchorGetting Started
anchor

If you are working with Android, Webex Teams allows you to integrate secure and convenient Webex Teams messaging and calling features in your Android apps.

The Webex Teams Android SDK gives you the ability to customize your app and to seamlessly access powerful Webex Teams collaboration features without ever having to leave your mobile app. Use the Android SDK to apply your own UI for customization and still use client-side API calls to embed Webex Teams voice and video calling directly into your application. With the Webex Teams Android SDK, you can also connect end users from your app to any Webex Teams app/device and SIP device.

In this guide, we'll show you how to create Webex Teams spaces, post messages, and make and receive audio/video calls.

Requirements
  • Android Studio 2.3 or later
  • Android SDK Tools 25 or later
  • Android API Level 21 or later
  • Java JDK 8
  • Gradle for dependency management
  • Webex Teams Account
  • Use of this SDK requires the spark:all scope
Step 1: Integrate the Webex Teams Android SDK

First, you need to add the following repository to your top-level build.gradle file of your project module in Android Studio.

To do this, open the Project Structure view and then open your build.gradle (Project: Your Application Name) file. Then, add mavenCentral() underneath the allprojects -> repositories code blocks, as shown below:

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://devhub.cisco.com/artifactory/webexsdk/'
        }
    }
}
Step 2: Add the Webex Teams Android SDK Library

Now you need to include the Webex Teams Android SDK library module as a dependency for your app.

To do this, add the following code and configuration to the dependencies block of the build.gradle (Module: app) file, as shown below:

dependencies {
    compile('com.ciscowebex:androidsdk:2.0.0@aar', {
        transitive = true
    })
}
Step 3: Enable Multidex Support and Update Packaging Options

In order for your app code to compile correctly after integration, you will need to enable multidex support for your app.

To do this, add multiDexEnabled true to the build.gradle (Module: app) file, under defaultConfig, as shown below:

android {
    defaultConfig {
        multiDexEnabled true
    }
}

Enabling multidex support allows your app build process to generate more than one (DEX) file when you compile your app. See the description of multidex in the Android documentation for more information.

You will also need to exclude the rxjava.properties file. To do this, add these packagingOptions to the build.gradle (Module: app) file, as shown below:

packagingOptions {
    exclude 'META-INF/rxjava.properties'
}

Configure the project to use ABI Filters and APK split, as shown below:

splits {
    abi {
        enable true
        reset()
        include 'armeabi-v7a'
        universalApk false
    }
}

Now, just sync the gradle dependencies to ensure that everything integrates properly.

Keep reading for details about how to use the Webex Teams Android SDK with your application, starting with authenticating the user, and then moving on to creating spaces and sending messages.

Step 4: App Integration and Authentication

Before your app can use Webex Teams on behalf of another user, you will need to register a Webex Teams Integration. Your app will either need to authenticate users via an OAuth grant flow for existing Webex Teams users, or via a Guest Issuer token for guest users that do not have a Webex Teams account.

Once registration is complete, you will get a Client ID and Client Secret for use with the app. These can be used to generate a token with the proper scopes.

See the examples below for creating new Webex instances for existing Webex Teams users or for guest users who do not have a Webex Teams account.

Example #1 - Create a new Webex instance using Webex Teams authentication (OAuth-based):
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
String scope = "spark:all";
String redirectUri = "Webexdemoapp://response";

OAuthWebViewAuthenticator authenticator = new OAuthWebViewAuthenticator(clientId, clientSecret, scope, redirectUri);
Webex webex = new Webex(activity.getApplication(), authenticator)
if (!authenticator.isAuthorized()) {
    authenticator.authorize(webView, new CompletionHandler<Void>() {
        @Override
        public void onComplete(Result<Void> result) {
            if (!result.isSuccessful()) {
                System.out.println("User not authorized");
            }
        }
    });
}
Example #2 - Create a new Webex instance using Guest Issuer authentication (JWT-based):
JWTAuthenticator authenticator = new JWTAuthenticator();
Webex webex = new Webex(activity.getApplication(), authenticator);
if (!authenticator.isAuthorized()) {
    authenticator.authorize(myJwt);
}
Using Webex Teams with your App

Now that you're authenticated, you can use Webex Teams. You can create a space, add users, and post messages using the SDK.

Create a space:

webex.spaces().create("Hello World", null, new CompletionHandler<Space>() {
    @Override
    public void onComplete(Result<Space> result) {
        if (result.isSuccessful()) {
            Space space = result.getData();
            String spaceId = space.getId();
        }
        else {
            WebexError error = result.getError();
        }
    }
});

Add users to the space:

webex.memberships().create(spaceId, null, "person@example.com", true, new CompletionHandler<Membership>() {
    @Override
    public void onComplete(Result<Membership> result) {
        if (result.isSuccessful()) {
            Membership membership = result.getData();
        }
        else {
            WebexError error = result.getError();
        }
    }
});

Post messages to the space:

webex.messages().post(spaceId, null, null, "Hello there", null, null, new CompletionHandler<Message>() {
    @Override
    public void onComplete(Result<Message> result) {
        if (result.isSuccessful()) {
            Message message = result.getData();
        }
        else {
            WebexError error = result.getError();
        }
    }
});
Webex Teams Audio/Video Calling

This is the most significant SDK feature which enables users to make and receive audio/video calls via Webex Teams. Calling in the SDK is very easy to use.

First, you need to register the device in order to send and receive calls:

webex.phone().register(new CompletionHandler<Void>() {
    @Override
    public void onComplete(Result<Void> result) {
        if (result.isSuccessful()) {
            // Device registered
        }
        else {
            // Device not registered, and calls will not be sent or received
        }
    }
});

Once registration is complete, you can make an outgoing call, as shown below:

webex.phone().dial("person@example.com", MediaOption.audioVideo(local, remote), new CompletionHandler<Call>() {
    @Override
    public void onComplete(Result<Call> result) {
        Call call = result.getData();
        if (call != null) {
            call.setObserver(new CallObserver() {
                @Override
                public void onRinging(Call call) {

                }

                @Override
                public void onConnected(Call call) {

                }

                @Override
                public void onDisconnected(CallDisconnectedEvent callDisconnectedEvent) {

                }

                @Override
                public void onMediaChanged(MediaChangedEvent mediaChangedEvent) {

                }
            });
        }
        else {
            WebexError error = result.getError();
        }
    }
});

These calls can be made to Webex Teams users/devices, Telepresence systems, SIP devices, and regular telephones. If the user calls a telephone system such as an IVR, the SDK also supports DTMF transport so users can navigate IVR menus.

To send DTMF, simply invoke call.send(dtmf, completionHandler):

// Send DTMF
Call.sendDTMF(dtmfEvent, new CompletionHandler<Void>() {
    @Override
    public void onComplete(Result<Void> result){

    }
});

To receive a call:

webex.phone().setIncomingCallListener(new Phone.IncomingCallListener() {
    @Override
    public void onIncomingCall(Call call) {
        call.answer(MediaOption.audioVideo(local, remote), new CompletionHandler<Void>() {
            @Override
            public void onComplete(Result<Void> result) {
                if (result.isSuccessful()) {
                    // success
                }
                else {
                    WebexError error = result.getError();
                }
            }
        });
    }
});
Complete Demo App

A complete demo application is available to see the complete functionality of the SDK.

anchorMigrating from the Cisco Spark Android SDK
anchor

If your project uses the Cisco Spark Android SDK, you will need to make a few changes when upgrading to the new Webex Android SDK.

  1. In your project's build.gradle file, change the repository URL:

    allprojects {
        repositories {
            jcenter()
            maven {
                // url 'https://devhub.cisco.com/artifactory/sparksdk/'
                url 'https://devhub.cisco.com/artifactory/webexsdk/'
            }
        }
    }
  2. Update the library dependency for your app:

    dependencies { 
        // compile('com.ciscospark:androidsdk:1.4.0@aar', {
        //     transitive = true
        // })
        compile('com.ciscowebex:androidsdk:2.0.0@aar', {
            transitive = true
        })
    }
SDK Usage Changes
SDK ChangeOld Spark SDKNew Webex SDK
Package namingcom.ciscospark.androidsdkcom.ciscowebex.androidsdk
Instance creationSpark spark = new Spark(application, authenticator)Webex webex = new Webex(application, authenticator)
Rooms are now spacesspark.rooms().get(roomId, CompletionHandler<Room> handler)webex.spaces().get(spaceId, CompletionHandler<Space> handler)
SparkError is now WebexErrorSparkError error = result.getError()WebexError error = result.getError()

We recommend that you replace any variables names containing "spark" with "webex" in your project's code.

anchorTroubleshooting the Android SDK
anchor

If you're having trouble with the Android SDK, here's some more information to help troubleshoot the issue.

SDK Requirements

Review the following SDK requirements to make sure you're using the correct minimum versions of Android Studio, Java JDK, etc.:

  • Android Studio 2.3 or later
  • Android SDK Tools 25 or later
  • Android API Level 21 or later
  • Java JDK 8
  • Gradle for dependency management
  • A Webex Teams account and integration with the spark:all scope
View the System Logs

The Webex Teams Android SDK uses the Android system logger utility to collect log messages that will allow you to define problem areas when troubleshooting.

Use the Logcat command-line tool to collect, view, and filter all SDK logs. The Android SDK provides the option to display all messages or just the messages that indicate the most severe errors. Set the log level to verbose to display all errors. See Write and View Logs with Logcat for more information.

webex.setLogLevel(Webex.LogLevel.VERBOSE);
Firewall Ports

The Android SDK makes use of the following network ports. If you're encountering connection issues, make sure there aren't any firewalls blocking or preventing communication over these ports.

ServiceProtocolPort(s)
MessagingHTTPS443
NotificationsWebSocket443
CallsHTTPS443
MediaRTP/SRTP over UDP/TCP33434-33598, 8000-8100 or 33434 (shared port)
SDK Dependencies

For more information about dependencies of the Android SDK, please refer to their documentation:

App Crashes

If your app is crashing, running a stack trace may help you determine the root cause. Please see Android’s Diagnose the Crashes for more information about determining the cause of Android app crashes.

Getting Support

If you're stumped, contact the Webex Developer Support team for more help with the SDK.

Last updated: December 10, 2018