/ringcentral-android

Primary LanguageJavaMIT LicenseMIT

RingCentral Android SDK

Build Status Bintray License

Table of contents

  1. Overview
  2. Installation
  3. Basic Usage
    1. Initialization
    2. Authentication
  4. Helper Examples
    1. RingOut
    2. SMS
    3. Call Log

Overview

This RingCentral Android SDK has been made to make Android development easier for developers who are using RingCentral Platform's suite of APIs. It handles authentication and the token lifecycle, makes API requests, and parses API responses. This documentation will help you get set up and going with some example API calls.

Installation

Android Studio Environment

Install SDK

You can install the RingCentral SDK via JCenter or by installing the AAR file locally.

Via JCenter

To add this SDK to your project from JCenter, add this line to your Gradle dependencies for your app. Here is the link to the online repository: https://bintray.com/ringcentral/maven/rc_android_sdk/view Add these to your app's Gradle dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.ringcentral.rcandroidsdk:rc_android_sdk:0.5'
}

Via Local AAR File

  1. Download AAR from the GitHub release page
  2. Move AAR file into your app module's libs directory
  3. Edit the app/build.gradle file to add the following Gradle script:
repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    ...
    compile 'com.ringcentral.library:ringcentral-android-0-7@aar'
}

Configure App Permissions

Add the follow permissions to your app module's AndroidManifest.xml (app/src/main/AndroidManifest.xml) within the <manifest> tag to utilize RingCentral capabilties:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

Import library

To import the SDK to your app, e.g. MainActivity, add this line:

import com.ringcentral.rc_android_sdk.rcsdk.*;

Basic Usage

Initialization

Create an instance of the global SDK object in your application, and configure it with your unique API key, secret, and server URL.

Production:
sdk = new SDK(appKey, appSecret, Platform.Server.PRODUCTION);
Sandbox
sdk = new SDK(appKey, appSecret, Platform.Server.SANDBOX);

Get Platform Singleton

Platform platform = sdk.platform();

With the oldPlatform singleton and the SDK configured with the correct server URL and API key, your application can authenticate to access the features of the API.

Authentication

Authentication is done by calling the oldPlatform.authorize() method with the username, extension(optional), and password. Also, because the login process is asynchronous, you have to call a new Callback() and pass that in as the last parameter. You can handle login success in the overriding of the Callback's onResponse(), such as performing updates to the user interface. To handle login failure, you can add error handling in onFailure().

 platform.login("username", "ext", "password", new Callback() {
                    @Override
                    public void onFailure(Request request, IOException e) {
                        //handle exception
                    }
                    @Override
                    public void onResponse(Response response) throws IOException {
                        try {
                            if (response.isSuccessful() && platform.loggedIn()) {
                                //set the current authorized platform instance to the singleton instance 
                                Singleton.getInstance().setPlatform(helpers);
                                //start activities
                                Intent optionsIntent = new Intent(ActivityA.this, ActivityB.class);
                                startActivity(optionsIntent);
                            }
                        } catch (Exception e) {
                            //handle exception
                        }
                    }
                });

####Checking Authentication State

To check in your Application if the user is authenticated, you can call the oldPlatform singleton's isAuthorized() method which will handle refreshing tokens for you, or throw an exception if the refreshed Access Token is invalid.

platform.loggedIn(); //returns boolean 

Android Demo app link:

https://github.com/vyshakhbabji/ringcentral-android-sdk-demoapp

License

RINGCENTRAL ringcental-android SDK is available under an MIT-style license. See LICENSE.md for details.

RINGCENTRAL ringcentral-android © by Vyshakh Babji, Andrew Pang