Android SDK Usage Examples
Initialize with dynamic tenant config
TenantConfigStore.load(this)?.let { cfg ->
BubblSdk.init(
application = this,
config = TenantConfigStore.toBubblConfig(cfg)
)
}
Refresh campaigns with location fallback
@SuppressLint("MissingPermission")
private fun refreshCampaignsWithLocation() {
LocationServices.getFusedLocationProviderClient(this).lastLocation
.addOnSuccessListener { location ->
if (location != null) {
BubblSdk.refreshGeofence(location.latitude, location.longitude)
} else {
BubblSdk.forceRefreshCampaigns()
}
}
.addOnFailureListener {
BubblSdk.forceRefreshCampaigns()
}
}
BubblSdk.updateSegments(listOf("vip", "early_access")) { success ->
if (success) {
// UI success state
} else {
// UI error state
}
}
Fetch and refresh privacy text
val cached = BubblSdk.getPrivacyText()
BubblSdk.refreshPrivacyText { refreshedText ->
if (refreshedText != null) {
// update UI
}
}
Observe geofence stream in Activity/Fragment
lifecycleScope.launch {
BubblSdk.geofenceFlow.collectLatest { snap ->
snap ?: return@collectLatest
// render polygons on map
}
}
Handle notification payloads and open custom modal
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
val json = intent.getStringExtra("payload")
?: intent.getStringExtra("notification_payload")
?: intent.getStringExtra("data")
?: return
val notification = Gson().fromJson(
json,
NotificationRouter.DomainNotification::class.java
)
ModalFragment.newInstance(notification)
.show(supportFragmentManager, "notification_modal")
}
Survey tracking and submission
BubblSdk.trackSurveyEvent(
notificationId = notification.id.toString(),
locationId = notification.locationId,
activity = "notification_delivered"
) { _ -> }
BubblSdk.submitSurveyResponse(
notificationId = notification.id.toString(),
locationId = notification.locationId,
answers = answers
) { success ->
// show success/failure UI
}