Skip to main content

Android SDK Reference

This documentation will guide you to implement the Withings SDK for Android.

Sample code

Get the SDK sample app here: https://github.com/withings-sdk/withings-sdk-sample-android

Minimum requirements

  • Android 7
  • Androidx

Add the Withings SDK dependencies

Add the dependency to your build.gradle:

repositories {
...
maven { url = "https://withings.jfrog.io/artifactory/androidsdk-mvn-prod/" }
}

dependencies {
...
implementation "com.withings.library:webble:6.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_version"
}

Add the library permissions

You will need some application permissions for the library to work.

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
caution

The Withings SDK will not require the user to turn ON the Bluetooth. It is recommended that your app ask the user to turn on Bluetooth.

How to manage location permission request

The Withings SDK will ask the user the location permission to enable BLE scan if the app has not. It is recommended that your app ask the user to enable location permission to provide the right level of information. For more information, please refer here.

If you're targeting Android 12, you won't need to ask the location permission for your Android 12 users. There are new bluetooth permissions more specific for our use case : BLUETOOTH_SCAN and BLUETOOTH_CONNECT.

The Withings SDK will ask the user those permissions if the app has not during device installation. But it is recommended that your app ask them first to provide the right level of information.

<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

Initialize the Withings SDK

Please follow the following steps to implement the Withings SDK:

  1. Add a WithingsFragment to your Activity and load your redirection URL for install or settings.
WithingsFragment.newInstance(myInstallUrl)
WithingsFragment.newInstance(myDevicesUrl, accessToken)
  1. Add the two callbacks :
  • setCloseIntentListener(...)
  • setNotificationListener(...)
  1. (Optional) If you want the SDK to look for device to synchronize, you can use the WithingsSyncService.

In your own implementation of the android.app.Application you con call :

WithingsSyncService.get(context).start(...) with the information of the specific devices you want to synchronize. You'll need to have the location permission for ir to work.

This service requires you to provide one or more Withings's devices tokens. There is two ways to get a device token:

  • After installing a Withings device with the SDK, you will receive a notification from your NotificationListener "Installation Success" with a parameter advertise_key which contains your device token. Notification section: SDK Notifications
  • Through the Withings API User v2 - Getdevice. This API lists your devices, the device token is stored with the advertise_key key.
  1. (Optional) You can also set a custom listener if you don't want it be output to logcat. Or maybe use firebase to collect the errors.
WebBluetooth.logger = object : WebBluetooth.Logger {
override fun debug(tag: String, message: String) {
yourLogger.log(tag, message)
}

override fun error(tag: String, message: String, error: Throwable) {
yourLogger.warn(tag, message)
FirebaseCrashlytics.getInstance().recordException(WithingsSDKException("$tag: $message", error))
}
}

Changlogs

Help

Login required

Please log in to your Developer Dashboard in order to file a request.

OK