Guide d’intégration Android
Ce guide vous explique comment intégrer le SDK Azeoo dans votre application Android en utilisant le flux initialize → connect.
Aperçu
- Initialiser –
AzeooSDK.initialize(context, apiKey, config, theme, ...)dans votreApplication(sans utilisateur). - Connecter –
AzeooSDK.shared.connectUser(token, gender, height, weight, callback)lorsque vous disposez d’un jeton utilisateur. - Utiliser les modules –
AzeooSDK.shared.modules.nutrition, puis intégrer des fragments ou appeler les méthodes du module.
Intégration de base
Étape 1 : Initialiser le SDK
Dans votre classe Application :
import android.app.Application
import com.azeoo.sdk.AzeooConfig
import com.azeoo.sdk.AzeooSDK
import com.azeoo.sdk.AzeooThemeConfig
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
AzeooSDK.initialize(
context = this,
apiKey = "your-sdk-api-key-here",
config = AzeooConfig(locale = "en", analyticsEnabled = true, offlineEnabled = true),
theme = AzeooThemeConfig(),
callback = { error ->
if (error == null) {
// SDK initialized
} else {
// Handle init error
}
}
)
}
}
Enregistrez votre application dans AndroidManifest.xml :
<application android:name=".MyApplication" ...>
</application>
Étape 2 : Connecter un utilisateur
Lorsque l’utilisateur est connecté, appelez connectUser :
AzeooSDK.shared.connectUser(
token = "user-token",
gender = "male",
height = AzeooHeight(178.0),
weight = AzeooWeight(75.0),
) { profile, error ->
if (error == null) {
Log.d("AzeooSDK", "Connected: ${profile?.id}")
} else {
Log.e("AzeooSDK", "Connect failed", error)
}
}
Étape 3 : Utiliser l’UI du SDK
Dans une Activity ou un Fragment, utilisez les modules une fois que le SDK est prêt :
import com.azeoo.sdk.AzeooSDK
if (AzeooSDK.isReady) {
val nutritionFragment = AzeooSDK.shared.modules.nutrition.getFragment()
// Add fragment to your container, or use modules.nutrition.showDiary() etc.
}
Exemple complet
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.azeoo.sdk.AzeooHeight
import com.azeoo.sdk.AzeooSDK
import com.azeoo.sdk.AzeooWeight
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
AzeooSDK.shared.connectUser(
token = "user-token",
gender = "male",
height = AzeooHeight(178.0),
weight = AzeooWeight(75.0),
) { _, error ->
if (error == null && AzeooSDK.isReady) {
findViewById<Button>(R.id.btnNutrition).setOnClickListener {
AzeooSDK.shared.modules.nutrition.showDiary(null)
}
} else {
Log.e("AzeooSDK", "Connect failed", error)
}
}
}
override fun onDestroy() {
super.onDestroy()
AzeooSDK.shared.dispose()
}
}
Gestion des erreurs
Gérer les erreurs d’initialisation et de connexion :
AzeooSDK.shared.connectUser(
token = userToken,
gender = gender,
height = height,
weight = weight,
) { _, error ->
if (error != null) {
Log.e("AzeooSDK", "Connect failed", error)
showError("Could not connect to SDK")
}
}
Prochaines étapes
- Configuration — Options de configuration du SDK
- Référence de l’API — Documentation de l’API
- Exemples — Davantage d’exemples