Android Rewarded Example
Both rewarded and rewarded interstitial ads offer users a reward for engaging with an ad.
In the example below, a rewarded ad is displayed when the menu item is clicked. This is a use-case for a rewarded ad.
The ad could also be displayed at natural breaks in the app (e.g between two screens) and automatically reward users for watching without explicit opt-in. This would be an example of a rewarded interstitial ad.
The event FuseAdViewEvent.Reward
will be sent each time a user earns a reward. You can use this event to trigger providing the user a reward in your app. For example, after watching a rewarded ad, you might give the user bonus points or unlock a new level.
class MainActivity : AppCompatActivity() {
private var rewardedAd = FuseFullScreenAdView(this, "<zone_code>").apply {
listener = object : FuseFullScreenAdViewListener {
override fun onEvent(
adView: FuseFullScreenAdView,
event: FuseAdViewEvent,
) {
val msg = when (event) {
is FuseAdViewEvent.Reward -> "Reward received: ${event.amount} of ${event.type}"
else -> null
}
msg?.let {
showSnackBar(it)
}
}
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.action_rewarded -> {
rewardedAd.show(this)
true
}
else -> super.onOptionsItemSelected(item)
}
private fun showSnackBar(message: String) {
Snackbar
.make(
this,
binding.root,
message,
Snackbar.LENGTH_SHORT,
)
.show()
}
}