Skip to main content

Getting started

Install and configure the Rook Training SDK.


Contents

  1. Prerequisites
  2. Install
  3. Configure
  4. Run & Call a test function
  5. Next steps

Prerequisites

IDE & Tools

  • Android Studio Chipmunk | 2021.2.1.
  • Kotlin 1.6.10 (JVM Target 1.8).
  • Android Device or Emulator with BLE capabilities and Android 6+ (sdk 23).

Android SDK

Go to your build.gradle (app level) and apply the following configuration.

android {
compileSdk 31

defaultConfig {
minSdk 23
targetSdk 31

// Other configurations
}

// More configurations
}

Android Permissions

Go to your AndroidManifest.xml and apply the following permissions.


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.rookmotion.rooktraining">

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

<!-- Optional for the sdk-utils library-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

<!-- Scan BLE peripherals -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<!-- Android 6+ (sdk 23) bluetooth permissions-->
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30"/>
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30"/>

<!-- Android 12+ (sdk 31) bluetooth permissions-->
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

<!-- Filter your app from devices that do not have BLE capabilities. -->
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true"/>

<!-- Other configurations -->
</manifest>

Install

Versioning

This SDK uses Semantic Versioning: major.minor.patch.

Incompatible changes increment major version, adding compatible changes increment minor version, and compatible fixes increment the patch version.

Each time a major release it made we'll provide you with a migration guide.

Install from maven central

Go to your build.gradle (app level) and declare the sdk-rook-training dependency, then sync your project.

dependencies {

// RookMotion
implementation 'com.rookmotion.android:sdk-rook-training:$rt_latest_version'
implementation 'com.rookmotion.android:sdk-utils:$u_latest_version' // Optional

// Other dependencies
}

The sdk-utils library contains utilities for network state, permissions, etc. You can avoid installing it and implement those utilities by yourself. The next tutorials will assume you installed it.

  • sdk-utils includes joda-time library, version 2.10.6 as a compile dependency.

Configure

To use our SDK you will need to initialize it every time your app launches. Follow the steps:

In your root package create a package named rm.

Create a class named RMServiceLocator with a context as a constructor parameter.

package com.rookmotion.rooktraining.rm

import android.content.Context

class RMServiceLocator(context: Context) {
}

Create a debug config in android > buildTypes of your build.gradle (app level) and add the following buildConfigFields

Then in AndroidStudio's toolbar go to Build > Make project to generate a BuildConfig file.

buildTypes {

// Release configuration

debug {
debuggable true

buildConfigField("String", "AUTH_TOKEN", "\"Bearer AUTH_TOKEN\"")
buildConfigField("String", "LEVEL_TOKEN", "\"LEVEL_TOKEN\"")
buildConfigField("String", "CORE_URL", "\"API_CORE_URL/api/v2/\"")
}
}

Inside RMServiceLocator create an RMSettings instance, add your credentials and enable core features.

package com.rookmotion.rooktraining.rm

import android.content.Context
import com.rookmotion.rooktraining.BuildConfig

class RMServiceLocator(context: Context) {

private val settings = RMSettings.getInstance().apply {
addAuth(BuildConfig.AUTH_TOKEN, BuildConfig.LEVEL_TOKEN)
enableCore(BuildConfig.CORE_URL)
}
}
  • Make sure your BuildConfig import is from your app package in this case is com.rookmotion.rooktraining.BuildConfig

Create an RMApiSettings instance, this will configure the requests logging and timeout options.

package com.rookmotion.rooktraining.rm

import android.content.Context
import com.rookmotion.rooktraining.BuildConfig

class RMServiceLocator(context: Context) {

// RMSettings configuration

private val apiSettings = run {
if (BuildConfig.DEBUG) { // Only log when is a debug build
RMApiSettings(ApiLogType.ADVANCED, 60000)
} else {
RMApiSettings(ApiLogType.NONE, 60000)
}
}
}
  • Make sure your BuildConfig import is from your app package in this case is com.rookmotion.rooktraining.BuildConfig

Create an RM instance and a RookMotion instance.

val rm: RM by lazy { RM.getInstance(context, settings, apiSettings) }
val rookMotion: RookMotion by lazy { RookMotion.getInstance(context, settings, apiSettings) }

In your root package create a class with the following convention YOUR_APP_NAME followed by Application, this class must extend from Application, then create an RMServiceLocator instance.

package com.rookmotion.rooktraining

import android.app.Application

class RookTrainingApplication : Application() {

val rmServiceLocator by lazy { RMServiceLocator(this) }
}

Go to your AndroidManifest.xml in the <application/> tag, and add the previous class under the name attribute.

<application
android:name=".RookTrainingApplication"
<!-- Other attributes -->

Logging

Rook Training SDK uses RMApiSettings to configure HTTP request logging, if you want to see logs for other operations, like RMTrainer's measurements, you will need to add Timber dependency.

dependencies {

// Timber
implementation 'com.jakewharton.timber:timber:5.0.1'

// Other dependencies
}

And plant a debug tree.

import com.rookmotion.rooktraining.BuildConfig

class RookTrainingApplication : Application() {

override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) { // Only log when in debug
Timber.plant(Timber.DebugTree())
}
}
}
  • Make sure your BuildConfig import is from your app package in this case is com.rookmotion.rooktraining.BuildConfig

Run & Call a test function

Now you are ready to use the Rook Training SDK, call a function to verify the status of a user using their email.

Go to an Activity or Fragment and access the rm instance through the rmServiceLocator of the RookTrainingApplication class.

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

(application as RookTrainingApplication).rmServiceLocator.rm
}
}

Call getUserStatusFromApi providing an email and a callback when the operation completes.

(application as RookTrainingApplication)
.rmServiceLocator
.rm
.getUserStatusFromApi("daniel.nolasco@rookmotion.com") { rmResponse, userStatus ->
Toast.makeText(
this,
"Success: ${rmResponse.isSuccess} Message: ${rmResponse.message} Code: ${rmResponse.code}",
Toast.LENGTH_LONG
).show()
}
  • This will return success on false and a code of 404, indicating the provided email is not associated with an account.

Next steps

Congratulations! You successfully installed and configured the Rook Training SDK, now before start coding you should go to the next tutorial to learn some definitions.