Aller au contenu principal

Android Integration Guide

This guide walks through integrating the Azeoo SDK into your Android app using the initialize → connect flow.

Overview

  1. InitializeAzeooSDK.init(context, apiKey, config, theme, ...) in your Application (no user).
  2. ConnectAzeooSDK.shared.connect(userId, token, callback) when you have a user and token.
  3. Use modulesAzeooSDK.shared.modules.nutrition, AzeooSDK.shared.modules.training, and embed fragments or call module methods.

Basic Integration

Step 1: Initialize the SDK

In your Application class:

import android.app.Application
import com.azeoo.sdk.AzeooSDK
import com.azeoo.sdk.AzeooConfig

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
AzeooSDK.init(
context = this,
apiKey = "your-api-key-here",
config = AzeooConfig(locale = "en", analyticsEnabled = true, offlineEnabled = true),
theme = AzeooThemeConfig(),
enableMultipleInstances = false
)
}
}

Register your Application in AndroidManifest.xml:

<application android:name=".MyApplication" ...>
</application>

Step 2: Connect a user

When the user is logged in, call connect:

AzeooSDK.shared.connect("user123", "auth-token") { result ->
result.onSuccess { Log.d("AzeooSDK", "Connected") }
result.onFailure { e -> Log.e("AzeooSDK", "Connect failed", e) }
}

Step 3: Use SDK UI

In an Activity or Fragment, use the modules after the SDK is ready:

import com.azeoo.sdk.AzeooSDK

if (AzeooSDK.shared.isReady) {
val nutritionFragment = AzeooSDK.shared.modules.nutrition.getFragment()
// Add fragment to your container, or use modules.nutrition.showDiary() etc.
}

Complete example

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.azeoo.sdk.AzeooSDK
import com.azeoo.sdk.AzeooConfig

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

AzeooSDK.shared.connect("user123", "auth-token") { result ->
result.onSuccess {
if (AzeooSDK.shared.isReady) {
findViewById<Button>(R.id.btnNutrition).setOnClickListener {
AzeooSDK.shared.modules.nutrition.showDiary(null)
}
findViewById<Button>(R.id.btnTraining).setOnClickListener {
AzeooSDK.shared.modules.training.showWorkouts()
}
}
}
result.onFailure { e -> Log.e("AzeooSDK", "Connect failed", e) }
}
}

override fun onDestroy() {
super.onDestroy()
AzeooSDK.shared.dispose()
}
}

Error handling

Handle init and connect errors:

AzeooSDK.shared.connect(userId, token) { result ->
result.onSuccess { /* proceed */ }
result.onFailure { e ->
Log.e("AzeooSDK", "Connect failed", e)
showError("Could not connect to SDK")
}
}

Next steps