Quick Start: Android
Minimal Requirements for SDK setup.
- Add the Huma SDK Maven repository to your project: Open your
settings.gradle.kts
file and add the following code to thedependencyResolutionManagement
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.
- Add the Huma SDK dependency to your project: Open your
build.gradle.kts
file and add the following code to thedependencies
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...")
}
- Add Huma gradle plugin to your project:
plugins {
id("com.huma.sdk.gradle-plugin") version "1.0.0"
}
- Download the
huma-sdk-config.json
file from the Huma workspace and add it to your project's app folder.- Log in to the Huma Workspace.
- Download the huma-sdk-config.json file.
- Add it to your project directory.
- Initialize Huma SDK in your Application class or using AppStartup library:
context.installHumaSdk()
- 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()
- 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.
- 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.