Skip to content

Repository files navigation

This repo is DEPRECATED. Check our newer Android SDK: https://github.com/webex/webex-android-sdk

Cisco Spark Android SDK

Travis CIlicense

The Cisco Spark™ Android SDK

The Cisco Spark Android SDK makes it easy to integrate secure and convenient Cisco Spark messaging and calling features in your Android apps.

This SDK is built with Android SDK Tools 27 and requires Android API Level 21 or later.

Table of Contents

Install

Assuming you already have an Android project, e.g. MySparkApp, for your Android app, here are the steps to integrate the Cisco Spark Android SDK into your project using Gradle:

  1. Add the following repository to your top-level build.gradle file:

    allprojects {
    repositories {
    jcenter()
    maven {
    url 'https://devhub.cisco.com/artifactory/sparksdk/'
    }
    }
    }
  2. Add the spark-android-sdk library as a dependency for your app in the build.gradle file:

    dependencies { compile('com.ciscospark:androidsdk:1.4.0@aar', {
    transitive =true
    })
    }
  3. Enable multidex support for your app:

    android {
    defaultConfig {
    multiDexEnabled true
    }
    }
  4. Exclude rxjava.properties in your packagingOptions :

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

Usage

To use the SDK, you will need Cisco Spark integration credentials. If you do not already have a Cisco Spark account, visit the Cisco Spark for Developers portal to create your account and register an integration. Your app will need to authenticate users via an OAuth grant flow for existing Cisco Spark users or a JSON Web Token for guest users without a Cisco Spark account.

See the Android SDK area of the Cisco Spark for Developers site for more information about this SDK.

Examples

Here are some examples of how to use the Android SDK in your app.

  1. Create a new Spark instance using Spark ID authentication (OAuth-based):

    StringclientId = "YOUR_CLIENT_ID";
    StringclientSecret = "YOUR_CLIENT_SECRET";
    Stringscope = "spark:all";
    StringredirectUri = "Sparkdemoapp://response";
    OAuthWebViewAuthenticatorauthenticator = newOAuthWebViewAuthenticator(clientId, clientSecret, scope, redirectUri);
    Sparkspark = newSpark(activity.getApplication(), authenticator)
    if (!authenticator.isAuthorized()) {
    authenticator.authorize(webView, newCompletionHandler<Void>() {
    @OverridepublicvoidonComplete(Result<Void> result) {
    if (!result.isSuccessful()) {
    System.out.println("User not authorized");
    }
    }
    });
    }
  2. Create a new Spark instance using Guest ID authentication (JWT-based):

    JWTAuthenticatorauthenticator = newJWTAuthenticator();
    Sparkspark = newSpark(activity.getApplication(), authenticator);
    if (!authenticator.isAuthorized()) {
    authenticator.authorize(myJwt);
    }
  3. Register the device to send and receive calls:

    spark.phone().register(newCompletionHandler<Void>() {
    @OverridepublicvoidonComplete(Result<Void> result) {
    if (result.isSuccessful()) {
    // Device registered
    }
    else {
    // Device not registered, and calls will not be sent or received
    }
    }
    });
  4. Create a new Cisco Spark space, add users to the space, and send a message:

    // Create a Cisco Spark space:spark.rooms().create("Hello World", null, newCompletionHandler<Room>() {
    @OverridepublicvoidonComplete(Result<Room> result) {
    if (result.isSuccessful()) {
    Roomroom = result.getData();
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
    // Add a user to a space:spark.memberships().create(roomId, null, "person@example.com", true, newCompletionHandler<Membership>() {
    @OverridepublicvoidonComplete(Result<Membership> result) {
    if (result.isSuccessful()) {
    Membershipmembership = result.getData();
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
    // Send a message to a space:spark.messages().post(roomId, null, null, "Hello there", null, null, newCompletionHandler<Message>() {
    @OverridepublicvoidonComplete(Result<Message> result) {
    if (result.isSuccessful()) {
    Messagemessage = result.getData();
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
  5. Make an outgoing call:

    spark.phone().dial("person@example.com", MediaOption.audioVideo(local, remote), newCompletionHandler<Call>() {
    @OverridepublicvoidonComplete(Result<Call> result) {
    Callcall = result.getData();
    if (call != null) {
    call.setObserver(newCallObserver() {
    @OverridepublicvoidonRinging(Callcall) {
    }
    @OverridepublicvoidonConnected(Callcall) {
    }
    @OverridepublicvoidonDisconnected(CallDisconnectedEventcallDisconnectedEvent) {
    }
    @OverridepublicvoidonMediaChanged(MediaChangedEventmediaChangedEvent) {
    }
    });
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
  6. Receive a call:

    spark.phone().setIncomingCallListener(newPhone.IncomingCallListener() {
    @OverridepublicvoidonIncomingCall(Callcall) {
    call.answer(MediaOption.audioVideo(local, remote), newCompletionHandler<Void>() {
    @OverridepublicvoidonComplete(Result<Void> result) {
    if (result.isSuccessful()) {
    // success
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
    }
    });
  7. Make an room call:

    spark.phone().dial(roomId, MediaOption.audioVideoSharing(newPair<>(localView,remoteView),shareView), newCompletionHandler<Call>() {
    @OverridepublicvoidonComplete(Result<Call> result) {
    Callcall = result.getData();
    if (call != null) {
    call.setObserver(newCallObserver() {
    @OverridepublicvoidonConnected(Callcall) {
    }
    //...@OverridepublicvoidonCallMembershipChanged(CallMembershipChangedEventcallMembershipChangeEvent) {
    CallMembershipmembership = callMembershipChangeEvent.getCallMembership();
    if (callMembershipChangeEventinstanceofMembershipJoinedEvent) {
    } elseif (callMembershipChangeEventinstanceofMembershipLeftEvent) {
    } elseif (callMembershipChangeEventinstanceofMembershipDeclinedEvent) {
    } elseif (callMembershipChangeEventinstanceofMembershipSendingVideoEvent) {
    } elseif (callMembershipChangeEventinstanceofMembershipSendingAudioEvent) {
    } elseif (callMembershipChangeEventinstanceofMembershipSendingSharingEvent) {
    }
    }
    });
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
  8. Receive screen share:

    spark.phone().dial(roomId, MediaOption.audioVideoSharing(newPair<>(localView,remoteView),shareView), newCompletionHandler<Call>() {
    @OverridepublicvoidonComplete(Result<Call> result) {
    Callcall = result.getData();
    if (call != null) {
    call.setObserver(newCallObserver() {
    @OverridepublicvoidonConnected(Callcall) {
    }
    //...@OverridepublicvoidonMediaChanged(MediaChangedEventmediaChangedEvent) {
    if (mediaChangedEventinstanceofRemoteSendingSharingEvent) {
    if (((RemoteSendingSharingEvent) mediaChangedEvent).isSending()) {
    mediaChangedEvent.getCall().setSharingRenderView(shareView);
    } elseif (!((RemoteSendingSharingEvent) mediaChangedEvent).isSending()) {
    mediaChangedEvent.getCall().setSharingRenderView(null);
    }
    }
    }
    });
    }
    else {
    SparkErrorerror = result.getError();
    }
    }
    });
  9. Start/stop sharing screen:

    activeCall.startSharing(r -> Ln.d("startSharing result: " + r));
    booleanisSharing = activeCall.isSendingSharing();
    activeCall.stopSharing(r -> Ln.d("stopSharing result: " + r));
  10. Post a message

    spark.message().post(
    idOrEmail, // person id, email or room idmessage, // text message to be sentmentions, // list of Mention objectfiles, // list of files to be sentnewCompletionHandler<Message>() {
    @OverridepublicvoidonComplete(Result<Message> result) {
    if (result.isSuccessful()) {
    // message sent success
    } else {
    // message sent failed
    }
    }
    }));
  11. Receive a message

    spark.message().setMessageObserver(
    newMessageObserver() {
    voidonEvent(MessageEventevent) {
    if (eventinstanceofMessageArrived) {
    Messagemessage = event.getMessage();
    // new message arrived
    } elseif (eventinstanceofMessageDeleted) {
    // message deleted
    }
    }
    }
    );

Contribute

Pull requests welcome. To suggest changes to the SDK, please fork this repository and submit a pull request with your changes. Your request will be reviewed by one of the project maintainers.

License

© 2016-2018 Cisco Systems, Inc. and/or its affiliates. All Rights Reserved.

See LICENSE for details.

About

This repo is DEPRECATED. Check our newer Android SDK

Resources

Stars

10 stars

Watchers

29 watching

Forks

Releases

Packages

Used by

Contributors

Languages