Android

Getting started

Example App Source Code

You can find a sample App implementation of the SDK here

For the sample App you need to provide a base url, an OAuth-Token and a ssl certificate. All informations can be found here

ToDo:

  • exceptions page

JavaDoc

For detailed description of the SDK methods you can find the JavaDocs here

Installation

Grab the latest SDK via Gradle:

implementation 'com.sensorberg.smartworkspace:sdk:VERSION'

to let Gradle download the SDK from our servers. You can find the latest VERSION on our Maven Repository. You also need to create a global gradle.properties file in USER_HOME/.gradle/

MAVEN_URL=http://maven.sensorberg.io/artifactory/smart-workspaces/
MAVEN_USERNAME=<username>
MAVEN_PASSWORD=<password>

replace <username> and <password> with the credentials provided by us.

To setup the maven repository in your app you have to open the build.gradle file of your app module (not the root) and add the following snippet:

repositories {
    maven {
        url MAVEN_URL
        credentials {
            username = MAVEN_USERNAME
            password = MAVEN_PASSWORD
        }
    }
}

Because of the changes and improvements of the Bluetooth API and BLE with Android 5.0 the Android minSdkVersion for our SDK is 21. So your project needs to set the minSdkVersion also to 21 or higher.

SDK Initialization

Use the SmartWorkspaceSdk.Builder to initialize the SDK

Kotlin
val sdk = SmartWorkspaceSdk.Builder(this)
            .baseUrl(BASE_URL)
            .oauthId(OAUTH_TOKEN)
            .certificate(CERTIFICATE)
            .build()
Java

You need to provide the BASE_URL of the server, the OAUTH_TOKEN to authenticate the app at the server and the SSL certificate CERTIFICATE of the server. All this information will be provided by us.

As of LiveData is the new way in Android to have lifecycle safe operations, our SDK is using LiveData. If you are not familiar with LiveData please visit the Android Developers Guide

If you like you can also view the JavaDocs to get an overview of all included methods.

Permissions

Following permissions will be merged to your projects AndroidManifest.xml automagicaly by Gradle

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

The only thing you have to do is to ask the user for location permission to use the SDK.

Logging

We are using Timber for logging in our SDK (See Timber GitHub). If you want to see the logging of the SDK use Timber and add an Timber.Tree to enable logging.

Kotlin
Timber.plant(object : Timber.Tree() {
    override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
        Log.d("DEBUG", message)
    }
})
Java

The SDK

The SDK have 3 main components: SmartWorkspaceSdk, UnitController and BookingManager

SmartWorkspaceSdk

This is the main entry point to access all the functions. From there one can login/logout, get status, get user and get UnitController and BookingManager

Unit Controller

Via the Unit Controller the app can access available and nearby units, filter by type and command them to open.
To acquire the single instance of the Unit Controller call sdk.getUnitController()

The Booking Manager

With the BookingManager you are able to create bookings of a room or a locker, delete bookings which are not started yet or end currently ongoing bookings.
To acquire the single instance of the Unit Controller call sdk.getBookingManager()