#kotlin #admob #admob-rewardedvideoad #rewardedvideoad
Вопрос:
Я попытался добавить рекламу с вознаграждением в свой проект, и после просмотра рекламы с вознаграждением часть fullScreenContentCallback так и не сработала. Объявление просматривается, но вознаграждение не добавляется.
Я открыл новый пустой проект и снова добавил коды.Я попробовал еще раз с помощью 1 кнопки и Texview и получил ту же ошибку.
Основная активность.тыс. т
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private var mRewardedAd: RewardedAd? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
loadAd()
binding.button.setOnClickListener {
showAd()
}
}
fun showAd() {
if (mRewardedAd != null) {
mRewardedAd?.show(this@MainActivity, OnUserEarnedRewardListener() {
fun onUserEarnedReward(rewardItem: RewardItem) {
var rewardAmount = rewardItem.amount
var rewardType = rewardItem.getType()
binding.reward.text = "Reward:2"
}
})
} else {
Log.d(TAG, "The rewarded ad wasn't ready yet.")
}
}
fun loadAd() {
var adRequest = AdRequest.Builder().build()
RewardedAd.load(this@MainActivity,"ca-app-pub-3940256099942544/5224354917", adRequest, object : RewardedAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
// Log.d(TAG, adError?.message)
mRewardedAd = null
}
override fun onAdLoaded(rewardedAd: RewardedAd) {
Log.d(TAG, "Ad was loaded.")
mRewardedAd = rewardedAd
}
})
mRewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
// Called when ad is shown.
Log.d(TAG, "Ad was shown.")
// currentJoker = 1
binding.reward.text = "Reward:2"
// binding.jokerValue.text="1"
// binding.jokerLayout.setBackgroundResource(R.drawable.jokericon)
}
override fun onAdFailedToShowFullScreenContent(adError: AdError?) {
// Called when ad fails to show.
Log.d(TAG, "Ad failed to show.")
}
override fun onAdDismissedFullScreenContent() {
// Called when ad is dismissed.
// Set the ad reference to null so you don't show the ad a second time.
Log.d(TAG, "Ad was dismissed.")
mRewardedAd = null
}
}
}
}
Код ошибки
E/Ads: Invalid event ID: null
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:557)
at java.lang.Long.parseLong(Long.java:636)
at com.google.android.gms.internal.ads.zzcaw.zzw(com.google.android.gms:play-services-ads@@20.2.0:3)
at com.google.android.gms.internal.ads.zzcaw.zzr(com.google.android.gms:play-services-ads@@20.2.0:6)
at com.google.android.gms.internal.ads.zzdfe.zzf(com.google.android.gms:play-services-ads@@20.2.0:3)
at com.google.android.gms.internal.ads.zzcxk.zza(com.google.android.gms:play-services-ads@@20.2.0:1)
at com.google.android.gms.internal.ads.zzdbc.run(com.google.android.gms:play-services-ads@@20.2.0:1)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
W/bileapps.adtes: Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
W/bileapps.adtes: Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
D/SurfaceUtils: disconnecting from surface 0xbc864808, reason disconnectFromSurface
W/Ads: #004 The webview is destroyed. Ignoring action.
I/chatty: uid=10135(com.etcmobileapps.adtest) identical 6 lines
W/Ads: #004 The webview is destroyed. Ignoring action.