Getting Started
This page takes you from an empty project to an initialized SDK: what you need, which modules to add, how to initialize the SDK and how the licence key works. When this is done, continue with the recommended set-up, which shows the whole flow of an app, from pairing to receiving data.
:::info Upgrading from SDK 2.x? SDK 3.0.0 stores its data with Room instead of Realm and has new build requirements. Read Migrating to 3.0 first. :::
Requirements
| Requirement | |
|---|---|
| Licence key | From Corsano, after the SDK agreement is signed. See Licence Key. |
Android version (minSdk) | API 23 (Android 6.0). The data module needs it, and every app needs the data module. |
compileSdk | 37 or above, for every module. |
| JDK | A JDK 21 toolchain. The SDK's artefacts are Java 21 class files, so your Android Gradle Plugin must be a version that can read Java 21 class files. |
| Kotlin | Kotlin 2.3 or later for the default artefacts. A project on Kotlin 2.2 uses the -kotlin2.2.21 artefacts, see below. |
| Network | The phone must reach https://api.health.cloud.corsano.com at least every two days for the licence check, see Licence Key. The usage report goes to the same host. |
| Phone | Bluetooth Low Energy. See the overview for the recommended hardware. |
Structure of Android SDK
The SDK is published on Maven Central as separate modules. Add the ones you need:
| Module | What it does | When you need it |
|---|---|---|
com.corsano.sdk:ble | Scans for the bracelet, connects to it, sends commands, transfers files and receives its notifications. | Always. |
com.corsano.sdk:data | Checks the licence key, downloads the bracelet's files automatically, decodes and stores the data, computes daily summaries and sleep, and runs the measurements (ECG, blood pressure calibration, SpO2 spot measurement, wearing optimization). | Always. It holds the licence check: from SDK 3.0.0 the ble and dfu modules do not work without it, see Licence Key. |
com.corsano.sdk:dfu | Updates the bracelet's firmware. | When your app updates the firmware. Recommended. |
com.corsano.sdk:ui | A ready-made wearing optimization screen. | Optional. |
com.corsano.sdk:bom is the SDK's bill of materials: it sets one version for all modules, see
Installing SDK to your project.
Three more modules come in by themselves. You do not declare them:
com.corsano.sdk:coreis a dependency of every module above.com.corsano.sdk:legacy-realmcomes withdata. It imports, once, the data a phone holds from SDK 2.x. An app that never shipped SDK 2.x can leave it out, see Migrating to 3.0.com.corsano.sdk:dfu-archivecomes withdfu. It holds the older firmware versions, see DFU SDK.
See the Change Log for the release history.
Installing SDK to your project
The artefacts are on Maven Central, so your project needs mavenCentral() in its repositories.
From SDK 3.0.0, declare the SDK through its bill of materials (BOM): name the version once, on the
BOM, and add the modules without a version. In the dependencies section of your app's
build.gradle:
dependencies {
// One version for every module of the SDK
implementation platform("com.corsano.sdk:bom:3.0.0")
// Bluetooth: scanning, connection, commands
implementation "com.corsano.sdk:ble"
// Licence check, automatic download, storage, summaries, measurements. Required.
implementation "com.corsano.sdk:data"
// Firmware update
implementation "com.corsano.sdk:dfu"
// Ready-made Wearing Optimization UI, optional
implementation "com.corsano.sdk:ui"
}
For build.gradle.kts:
dependencies {
// One version for every module of the SDK
implementation(platform("com.corsano.sdk:bom:3.0.0"))
// Bluetooth: scanning, connection, commands
implementation("com.corsano.sdk:ble")
// Licence check, automatic download, storage, summaries, measurements. Required.
implementation("com.corsano.sdk:data")
// Firmware update
implementation("com.corsano.sdk:dfu")
// Ready-made Wearing Optimization UI, optional
implementation("com.corsano.sdk:ui")
}
:::warning All modules must have the same version
The modules of the SDK only work together when they are all of the same version. Two different
versions in one app fail at runtime with NoClassDefFoundError or NoSuchMethodError. The BOM
takes care of this. Do not pin a single module to another version with strictly, force or a
resolution strategy.
:::
Projects on Kotlin 2.2
Every release is published twice from the same sources. If your project builds with Kotlin 2.2,
use the BOM whose version ends in -kotlin2.2.21:
implementation platform("com.corsano.sdk:bom:3.0.0-kotlin2.2.21")
The classes and the API are the same in both.
Permissions and R8
- The SDK's manifests declare the permissions it needs (Bluetooth, location for scanning on older Android versions, foreground service, notifications, internet). They are merged into your app's manifest. Your app still has to ask the user for the runtime permissions before it scans or connects, see Pairing.
- The SDK ships its own R8 / ProGuard rules. An app that shrinks with R8 needs no extra rules for the SDK.
Initializing SDK
Initialize the SDK once, in Application.onCreate(). Not in an Activity: the SDK schedules
background work (automatic download, reconnection, the usage report), and Android can start your
process for that work without opening any screen. The SDK must be initialized by then.
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// 1. Data module: the licence key is mandatory.
val dataConfig = DataSdk.Config(
licenceKey = "my_key",
slotsIntervalSecs = 10 * 60, // daily summaries in 10-minute slots
licenceListener = object : LicenceListener {
override fun onLicenceLocked(error: LicenceError) {
// The SDK stopped working with the bracelet. See "Licence Key" below.
}
override fun onLicenceUnlocked() {
// The SDK works again.
}
},
)
// 2. DFU module: the Activity opened when the user taps the update notification.
val dfuConfig = CorsanoDfu.Config(notificationTarget = MainActivity::class.java)
// 3. Initialize every module you added with one call.
val config = CorsanoSdkConfig.Builder()
.logger(SdkLogger.LogCat(if (BuildConfig.DEBUG) Log.DEBUG else Log.WARN))
.addModuleConfig(dataConfig)
.addModuleConfig(dfuConfig)
.build()
CorsanoSdk.initialize(this, config)
// 4. Let the SDK initialize every bracelet when it connects.
DataSdk.getInstance().getManager().enableAutoInitialization(
InitializationConfig(
braceletPlan = DevicePlan.CONTINUOUS_GREEN_INTERMITTENT_MULTICOLOR,
samplingRate = SampleRate.ONE_MIN,
)
)
}
}
What each step does:
DataSdk.Configholds the licence key and the options of the Data module. All of them are described in Data SDK, Configuration. Without this config the SDK has no licence key and does not work.CorsanoDfu.Configis only needed if you added thedfumodule. See DFU configuration.CorsanoSdk.initializeinitializes all the modules in your build. Thebleanddfumodules need no config of their own; thedatamodule needs its config for the licence key. Call it once: a second call throwsIllegalStateException("Already initialized").enableAutoInitializationtells the SDK which plan and sampling rates to give the bracelet. Use the plan and the rates agreed with Corsano for your project; the values above are an example.
:::warning A bracelet must be initialized on every connection
From SDK 2.0.0 a bracelet accepts commands only after it has been initialized on the current
connection (authentication, time, plan, sampling rates). Until then every command fails with
NotInitializedException. The enableAutoInitialization call above does this for you on every
connection. See Bracelet Initialization.
:::
After CorsanoSdk.initialize you reach each module through its own entry point:
| Module | Entry point |
|---|---|
ble | BleSdk.getInstance() |
data | DataSdk.getInstance(), then getManager() and getDownloadManager() |
dfu | CorsanoDfu.getInstance() |
Licence Key
The licence key is mandatory. You receive it from your Corsano account manager when the SDK
agreement is signed; use our contact page if you do not have
one. The key is valid for the duration of your subscription. You pass it in
DataSdk.Config(licenceKey = …).
Two rules follow from the way the key is checked. Plan for them from the start:
- Every app needs the
datamodule and a key, also an app that only sends Bluetooth commands or only updates firmware. Without them the SDK is locked. - Every phone needs a connection that reaches
api.health.cloud.corsano.comat least every two days. After two days without a confirmed check, the SDK locks until the phone is online again.
How the key is validated
1. The key must be present. If licenceKey is null, CorsanoSdk.initialize() throws
IllegalArgumentException at once, on the calling thread.
2. The key is checked with the Corsano cloud, in the background, at every start of your app.
initialize() does not wait for the result. A failed check never throws and never crashes your
app (up to SDK 2.3.0 it did). The result is the licence state:
LicenceState | Meaning | Does the SDK work? |
|---|---|---|
NotChecked | No check has finished since the app started. | Yes |
Valid | The Corsano cloud confirmed the key. | Yes |
Unverified | The check could not be completed: no network, a captive portal, a proxy, an unexpected answer. | Yes, as long as the Corsano cloud confirmed the key on this phone in the last two days. It does not lift a lock. |
Locked(reason) | The SDK is locked for the reason below. | No, see below. |
The SDK checks the key at every start of the app and, when a network is there, twice a day in the
background. DataSdk.recheckLicence() checks at once.
The reasons for a lock (LicenceError):
LicenceError | Meaning | What to do |
|---|---|---|
Unknown | The Corsano cloud does not know the key. | Check the key for typing errors. Contact Corsano. |
Expired(startDate, endDate) | The subscription ended on endDate, or only starts on startDate. A date is null when the cloud sent none. | Renew the subscription with Corsano. |
PhoneDateInvalid | The phone's date is wrong, so the secure connection to the Corsano cloud failed. | Ask the user to switch on the automatic date and time, then call DataSdk.recheckLicence(). |
NotConfirmed | The Corsano cloud has not confirmed the key on this phone for two days, and the last check could not be completed (no network, or a network that does not reach the Corsano cloud). | Give the phone a connection that reaches api.health.cloud.corsano.com, then call DataSdk.recheckLicence(). |
NoLicenceKey | The SDK was initialized without the data module, so there is no key to check. | Add com.corsano.sdk:data and pass DataSdk.Config(licenceKey = …) to CorsanoSdk.initialize. See Apps that use only Bluetooth or firmware update. |
The two days of NotConfirmed count from the last check that confirmed the key. For a key that
was never confirmed on the phone (a new install, or the first start after an upgrade to 3.0.0) they
count from the first check that could not be completed.
What a locked SDK does
While the state is Locked:
- Everything that reaches the bracelet or produces new data fails with
SdkLicenceException, through the usual error channel of the call: theonErrorof a command or a manager, a failedResult,DfuListener.onDfuFailedwithDfuError.LICENCE_LOCKED(-32). A scan is not started: its listener getsBleScanEvent.BleScanFailedwitherrorCode == BleScanFailed.LICENCE_LOCKED(-32).connectopens no connection. - Background work stops: the automatic download, the reconnection and the usage report. It starts again by itself when a check unlocks the SDK.
- The data already on the phone stays readable, exportable and deletable through the repositories, so your app can still upload it.
- A measurement that was running can still be stopped (ECG, wearing optimization, blood pressure calibration), so the bracelet does not stay in it.
How long a lock lasts:
- A lock for
Unknown,ExpiredorNotConfirmedis stored. It is back in place at the next start of the app, also without a network, and stays until a check confirms the key: at a start of the app, at a background check, or when you callDataSdk.recheckLicence(). - A lock for
PhoneDateInvalidis not stored. It lasts until the next start of the app, which checks again, or until you callDataSdk.recheckLicence()after the user corrected the date. - A lock for
NoLicenceKeyis not lifted by a check. It needs the change to your app described below.
SdkLicenceException.reason holds the LicenceError. Retrying a call does not lift a lock, so
check for this exception before you treat an error as a bracelet problem.
Reacting to the licence state
Give the SDK a LicenceListener in DataSdk.Config. It is called on the callback scheduler (the
main thread by default), once per change, and also at the start of the app when a stored lock is
put back:
import com.corsano.sdk.data.LicenceListener
import com.corsano.sdk.licence.LicenceError
val dataConfig = DataSdk.Config(
licenceKey = "my_key",
licenceListener = object : LicenceListener {
override fun onLicenceLocked(error: LicenceError) {
when (error) {
LicenceError.PhoneDateInvalid -> showSetAutomaticDate() // then DataSdk.recheckLicence()
LicenceError.NotConfirmed -> showConnectToInternet() // then DataSdk.recheckLicence()
LicenceError.Unknown -> showContactSupport()
is LicenceError.Expired -> showContactSupport(error.endDate)
LicenceError.NoLicenceKey -> Unit // never reported here, see below
}
}
override fun onLicenceUnlocked() = hideLicenceMessage()
},
)
Two more calls are available at any time:
DataSdk.licenceStateis aStateFlow<LicenceState>with the current state. Collect it instead of, or next to, the listener. It can be read before the SDK is initialized (it isNotCheckedthen).DataSdk.recheckLicence()checks the key again in the background. The result arrives throughlicenceStateand the listener. Call it after the user corrected the phone's date, when the network comes back on a phone that is often offline, or from a "Try again" button.
Phones that are often offline
A phone that cannot reach api.health.cloud.corsano.com for more than two days locks the SDK
(NotConfirmed). While it is locked, nothing is downloaded from the bracelet. The download
starts again when a check confirms the key. If your phones work
behind a firewall, a proxy or a mobile device management profile, allow that host. If they are
offline for long periods by design, talk to Corsano before you roll out.
Apps that use only Bluetooth or firmware update
Up to SDK 2.3.0 an app with only the ble module (and dfu) ran without a licence key. From
3.0.0 it does not: an SDK that is initialized without the data module is locked from the start
with LicenceError.NoLicenceKey. Scans end with BleScanFailed.LICENCE_LOCKED, connect opens
no connection, commands fail with SdkLicenceException and startDfu fails with
DfuError.LICENCE_LOCKED. If that is your app:
-
Add
com.corsano.sdk:datanext toble(it needsminSdk23). -
Pass your key when you initialize the SDK:
CorsanoSdk.initialize(context,CorsanoSdkConfig.Builder().addModuleConfig(DataSdk.Config(licenceKey = "my_key")).build(),) -
Do not remove the Data module's initializer (
com.corsano.sdk.data.internal.init.DataSdkInitializerFactory) from your merged manifest. An app that removes it is locked the same way.
You need not call anything else of the Data module. NoLicenceKey is not reported to a
LicenceListener, because the listener belongs to the Data module: you see it as the reason of
the SdkLicenceException.
The licence and raw data
Your licence also decides which raw data the automatic download fetches from the bracelet. The activity, sleep, HRV and log files are always downloaded. These are downloaded only when your licence includes them:
| Raw data | File on the bracelet |
|---|---|
| PPG2 (multicolor PPG) | FileOnWatch.PPG2, and FileOnWatch.STRESS_FILE (EmoGraphy, see Stress data) |
| PPG (green) | FileOnWatch.PPG |
| Accelerometer | FileOnWatch.ACC_FILE |
| BioZ | FileOnWatch.BIOZ |
| ECG | FileOnWatch.ECG |
| Raw temperature | FileOnWatch.GREENTEG |
The SDK learns this list from a successful licence check and keeps it on the phone. If a raw stream you expect never arrives, check with Corsano what your licence includes, and make sure the phone has been online for at least one start of the app, before you debug the bracelet. See also Enable raw streams.
Other parameters
All parameters of the Data module (slot intervals, raw file sizes, reconnection interval, database encryption) are described in Data SDK, Configuration.
DFU configuration
CorsanoDfu.Config has two optional parameters:
| Parameter | Default | Meaning |
|---|---|---|
notificationTarget | null | The Activity that opens when the user taps the notification shown during a firmware update. |
logger | null | A logger for the DFU module alone. Without it the module uses the SDK's logger. |
val dfuConfig = CorsanoDfu.Config(notificationTarget = MainActivity::class.java)
val config = CorsanoSdkConfig.Builder()
.addModuleConfig(dfuConfig)
.build()
CorsanoSdk.initialize(context, config)
See DFU SDK for the update itself. Read it before you update bracelets in the field: the default firmware of SDK 3.0.0 for the 287-2B is 9.50, and a bracelet on firmware 9.42 or later cannot be downgraded to a lower major version.
Logger configuration
CorsanoSdkConfig.Builder also sets the logger and the threads the SDK uses:
val config = CorsanoSdkConfig.Builder()
.logger(SdkLogger.LogCat(level = Log.INFO))
.callbackScheduler(Scheduler.MAIN)
.commandScheduler(Scheduler.newThread("ble-handler"))
.build()
CorsanoSdk.initialize(context, config)
| Builder call | Default | Meaning |
|---|---|---|
logger | SdkLogger.LogCat() (level Log.VERBOSE) | Where the SDK logs. SdkLogger.LogCat(level) writes to Logcat from that level up; implement SdkLogger to send the logs elsewhere. The SDK also keeps its own log files, see SDK logs. |
callbackScheduler | Scheduler.MAIN | The thread your callbacks and listeners are called on. By default the main thread, so you can update the UI directly. |
commandScheduler | A thread of the SDK's own | The thread the Bluetooth commands run on. |
dataScheduler | A thread of the SDK's own | The thread the Data module decodes and stores on. |
Most apps only set the logger and keep the default threads.
Next steps
- Recommended set-up: the whole flow of an app, step by step.
- Pairing: find and connect a bracelet.
- Data SDK: receive and read the data.