Exemples du SDK Android
Exemples de code du flux actuel du SDK Azeoo : initialize → connectUser → utiliser modules et user / theme.
Préparer l’application
import android.app.Application
import com.azeoo.sdk.AzeooConfig
import com.azeoo.sdk.AzeooSDK
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
AzeooSDK.initialize(
context = this,
apiKey = "your-sdk-api-key",
config = AzeooConfig(
locale = "en",
analyticsEnabled = true,
offlineEnabled = true,
),
callback = { error ->
if (error != null) {
// Handle initialization error
}
},
)
}
}
Connexion et affichage d’un module
// After user login
AzeooSDK.shared.connectUser(
token = "user-token",
gender = "male",
height = AzeooHeight(178.0),
weight = AzeooWeight(75.0),
) { _, connectError ->
if (connectError == null) {
// Wait for SDK ready if needed
AzeooSDK.onReady { readyResult ->
readyResult.onSuccess {
supportFragmentManager.beginTransaction()
.replace(R.id.container, AzeooSDK.shared.modules.nutrition.getFragment())
.commit()
}
}
}
}
Activity : boutons pour ouvrir des écrans
findViewById<Button>(R.id.btnDiary).setOnClickListener {
AzeooSDK.shared.modules.nutrition.showDiary(null)
}
findViewById<Button>(R.id.btnScanner).setOnClickListener {
AzeooSDK.shared.modules.nutrition.showScanner()
}
Utilisateur et thème
AzeooSDK.shared.user.getProfile { profileResult ->
profileResult.onSuccess { profile -> /* use profile */ }
}
AzeooSDK.shared.theme.setDarkMode { result ->
result.onFailure { error -> /* handle error */ }
}
AzeooSDK.shared.disconnect { error ->
if (error == null) {
// user logged out
}
}
Application d’exemple complète
Consultez le projet example/android dans le dépôt pour une application complète (connexion, navigation bottom et intégration du SDK).