Tutorial: Quickstart

Android Quickstart

Configure your Android project


Using [[service]] repositories...

  1. No special configuration is required in the build.gradle, as the android library is available on the Maven Central repository:
    allprojects {
     repositories {
         mavenCentral()
     }
    }
  2. Declare the android library as a project dependency. The library's resources and permissions will be merged automatically with yours.
    In the build.gradle file of your modules (don't forget to replace <target-version> with the desired version):
    dependencies {
     compile 'com.orange.webcom:sdk-android:<target-version>'
    }

...Or using library file

  1. Download the SDK library at:
    https://oss.sonatype.org/content/repositories/releases/com/orange/webcom/sdk-android/<version>/sdk-android-<version>.aar

  2. Save it in the aars/ folder of your modules.

  3. Declare dependencies in the build.gralde file of your modules:

repositories {
    flatDir {
        dirs 'aars'
    }
}
dependencies {
    compile 'com.orange.webcom:sdk-android:+@aar'
    // SDK dependencies
    compile 'org.mozilla:rhino:1.7.7.1'
    compile 'com.orhanobut:logger:1.15'
    compile 'com.koushikdutta.async:androidasync:2.2.1'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.3'
    compile 'com.android.support:customtabs:27.1.0'
}

Manage the conflicting files merged from dependent libraries

The Android SDK for [[service]] uses itself 3rd-party open source libraries. Their license files may conflict when Android Studio builds your project, as they are usually named the same way. To avoid this, you can include in the build.gradle file of your modules:

android {
    packagingOptions {
        pickFirst 'LICENSE.txt'
        pickFirst 'META-INF/LICENSE'
        pickFirst 'META-INF/NOTICE'
    }
}

Note: As most of open source licenses require to be included in your software, don't forget to include them by other means before distributing it.

Start coding


API is similar to the web SDK [[snippet]]:

Webcom myRef = new Webcom("[[baseUrl]]/base/<your-app>");

// Read data
myRef.on(Query.Event.CHILD_ADDED, new OnQuery() {
  @Override
  public void onComplete(DataSnapshot snapData, @Nullable String prevName) {
    // code to handle current data
    Map<String, Object> data = (Map) snapData.value();
  }
  @Override
  public void onCancel(WebcomError error) {
    // event subscription was canceled because of permission reason
  }
  @Override
  public void onError(WebcomError error) {
    // an error occured
  }
});

// Write data
myRef.set(new HashMap() {
  { put("foo", new HashMap() {
    { put("bar", "baz"); }
  }); }
});

See the API reference for more details.