Function "onUserEarnedReward" is never used in admob

Suraj Bahadur
By -
10 minute read
0

This issue is related to the google AdMob library i.e 20.1.0. There are many breaking changes coming in version 20.0.0 as it introduces many new APIs, deprecates many classes and APIs, and renaming many classes. Furthermore, you check out this link for complete migration.

Below is the sample code I've mentioned in both methods to get a callback of earned reward.


private fun showRewardedAds() {
val adRequest = AdRequest.Builder().build()
RewardedAd.load(requireContext(), getString(R.string.reward_id), adRequest, object : RewardedAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
if (isAdded)
hideProgress()
}
override fun onAdLoaded(rewardedAd: RewardedAd) {
hideProgress()
Log.d("TAG", "Ad was loaded.")
mRewardedAd = rewardedAd
//Implement this way.
mRewardedAd?.show(requireActivity()) {
val rewardAmount = it.amount
var rewardType = it.type
Log.d("TAG", "Ad was loaded. point earned $rewardAmount")
showMessage("Congratulation!! Theme Unlocked")
showRestartAppDialog()
}
//Dont implmented this way as onUserEarnedReward will not be called after watching the full video
mRewardedAd?.show(requireActivity(), OnUserEarnedRewardListener() {
fun onUserEarnedReward(rewardItem: RewardItem) {
val rewardAmount = rewardItem.amount
var rewardType = rewardItem.type
Log.d("TAG", "Ad was loaded. point earned $rewardAmount")
}
})
}
})
}
view raw AdmobTest.kt hosted with ❤ by GitHub

Tags:

Post a Comment

0Comments

Post a Comment (0)