Skip to main content

Quick Start: Android

Minimal Requirements for SDK setup.

  1. Add the Huma SDK Maven repository to your project: Open your settings.gradle.kts file and add the following code to the dependencyResolutionManagement section:
maven {
// TODO: wil be replaced with the actual public url
url = uri("https://maven.pkg.github.com/huma-engineering/huma-android-sdk")
credentials {
username = "***"
password = "***"
}
}

Note: Replace *** with your GitHub username and GitHub token.

  1. Add the Huma SDK dependency to your project: Open your build.gradle.kts file and add the following code to the dependencies section:
dependencies {
// Other dependencies...

// Install complete SDK bundle
implementation("com.huma.sdk:bundle:2.x.x")

// Or install individual modules
implementation(platform("com.huma:android-sdk-bom:2.x.x"))
implementation("com.huma.sdk:appkit")

/* Plugin dependencies */
// Replace with the actual Plugin modules
implementation("com.huma.sdk:plugins-...")
// Replace with the actual Plugin device module
implementation("com.huma.sdk:plugin-device...")
// Replace with the actual Plugin Huma module
implementation("com.huma.sdk:plugin-module...")
// Replace with the actual Plugin widget module
implementation("com.huma.sdk:plugin-widget...")
}
  1. Add Huma gradle plugin to your project:
plugins {
id("com.huma.sdk.gradle-plugin") version "1.0.0"
}
  1. Download the huma-sdk-config.json file from the Huma workspace and add it to your project's app folder.
    1. Log in to the Huma Workspace.
    2. Download the huma-sdk-config.json file.
    3. Add it to your project directory.

config file place

  1. Initialize Huma SDK in your Application class or using AppStartup library:
context.installHumaSdk()
  1. If you will use Huma SDK as an integration to your project you need to create AuthenticationProvider
class MyAuthenticationProvider : AuthenticationProvider {
override suspend fun onTokenRequired(reason: Reason): AuthData? {
// do a call to your backend to obtain huma session
}
}

Where AuthData is a data class that contains the auth token and refresh token.

data class AuthData(
val authToken: String,
val refreshToken: String,
)

Then register this class in SDK initializer

context.installHumaSdk {
sdk {
authKit {
authProvider(MyAuthenticationProvider())
// or
autoInitAuthProvider(MyAuthenticationProvider())
}
}
}

If AuthenticationProvider is registered with autoInitAuthProvider method, SDK will automatically call onTokenRequired on the app start.

In on other case, when it's registered with authProvider method, you should do this call when your are ready to authorise the user.

HumaAuthKitManager.getInstance().authorize()
  1. To get started with you screen, you can use the following code:
val humaAppKitManager = HumaAppKitManager.getInstance(context)
val screen = humaAppKitManager.findScreen("screenId")

After this steps you can start using Huma SDK in your project. To get more information about the configuration options please refer to the Getting Started section.

  1. To create a new device integration module, you need to create a new DeviceIntegration
class MyDevice : DeviceIntegration {

override val name: String = "Sample Device"
override val manufacturer: String = "Sample Manufacturer"
override val model: String = "Sample Model"
override val isDeviceConnected: Boolean =
true / false //return true if the device is connected, it will be used to show the connected state in the UI
override val canConnectToDevice: Boolean =
true / false //return true if the device can be connected, it will be used to show the connect button in the UI
override val supportedModuleDataTypes: List<KClass<out ModuleDataType<*>>> =
listOf(MyDataType::class)
override val lastSyncDateTime: Long? =
null //return the last sync date time, it will be used to show the last sync date time in the UI

override suspend fun onConnectToDevice(context: Context): Intent {
return Intent(context, MyConnectActivity::class.java)
}

override suspend fun onDisconnectFromDevice(context: Context): Intent? {
//disconnect from the device without UI
disconnectFromDevice()
return null
//disconnect from the device with UI
return Intent(context, MyDisconnectActivity::class.java)
}
}

Then create provider for this device integration

class MyDeviceIntegrationProvider : DeviceIntegrationProvider {

override fun getDeviceIntegrations(): List<DeviceIntegration> {
return listOf(MyDevice()) //return list of device integrations, if your plugin has multiple devices, return all of them here or separate them into different providers
}
}

Then register this class in SDK initializer

context.installHumaSdk {
sdk {
deviceIntegration {
registerDeviceProvider(
MyDeviceIntegrationProvider(),
... //register other providers if needed
)
}
}
}

For more information, please refer to the Device Integration section.