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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
}) | |
} | |
}) | |
} |