When to setup the NeoDay SDK
You can setup the NeoDay SDK as soon as the app starts — preferably in your Application class. This means you don't have to authenticate your user until you have determined that they are logged in to your app.
If your app can be experienced without the user being logged in, you can authenticate with NeoDay, but in this state the SDK does not know who the user is and not all functionality may be available until the user is authenticated.
Opening the app after QR code is scanned and going to a Gamification screen
The QR code contains a URL and code that can be submitted to NeoDay for a specific Campaign. Your app must know the Campaign ID.
Once your app can handle deep links from the camera app and extract the URL, do the following:
- Ensure the NeoDay SDK is configured and the user is authenticated.
- Call:
neoDaySDK.participate(
participationMethod = ParticipationMethod.CodeSubmission(campaignId = campaignId, code = code)
) { result ->
result
.onSuccess {
// Update UI state or navigate as needed
}
.onFailure { error ->
// Log error and update UI state accordingly
Log.e("NeoDaySDK", error.message ?: "Unknown error", error)
}
}
Here, campaignId is the Campaign ID and code is the full URL passed to your app.
- If submission is successful, the
NeoDayDeepLinkListeneris triggered and receives a factory callback returning aNeoDayViewController. You can get a Composable view viaNeoDayViewController.getView()?.invoke()to display the gamification screen.
Reference: Participating with a Campaign
Setting a Background Image on NeoDayViewController
To add a background image, assign a Composable to NeoDayViewController.background:
@Composable
fun BackgroundImage() {
Image(
painter = painterResource(R.drawable.background_image),
contentDescription = "Background image",
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
}
viewController.background = { BackgroundImage() }
Setting a Background Color on NeoDayViewController
You can also use a Composable with a Box and a background color:
@Composable
fun BackgroundColor() {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Red)
)
}
viewController.background = { BackgroundColor() }
Full implementation example
@Composable
fun CampaignOverviewScreen(
neoDaySDK: NeoDaySDK,
fragmentManager: FragmentManager
) {
val campaignViewController = remember { mutableStateOf<NeoDayViewController?>(null) }
LaunchedEffect(Unit) {
neoDaySDK.makeCampaignsOverview(
filter = CampaignTypeFilter.ShowOnly(listOf(CampaignType.Gamification))
) { result ->
result
.onSuccess { viewController ->
campaignViewController.value = viewController
}
.onFailure { error ->
// Log error and update UI state accordingly
Log.e("NeoDaySDK", error.message ?: "Unknown error", error)
}
}
}
// Rendered after SDK call completes — triggers recomposition
campaignViewController.value?.apply {
backButtonListener = {
// Navigate to the previous screen or close the current view
}
// Needed when the SDK cannot resolve a FragmentManager itself - e.g. hosting
// inside a Fragment (use childFragmentManager) or a Compose dialog.
this.fragmentManager = fragmentManager
// Must be set before invoking getView().
background = {
Image(
painter = painterResource(R.drawable.background_image),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
}
// Calls the SDK-provided Composable lambda to render the view into the current composition
getView()?.invoke()
}
}