admob 改写广告不显示 kotlin
Posted
技术标签:
【中文标题】admob 改写广告不显示 kotlin【英文标题】:admob rewords ads not showing kotlin 【发布时间】:2021-09-18 23:51:05 【问题描述】:横幅广告和插页式广告工作正常,但改写广告没有显示我的代码中的问题 这是我的代码 更新后我没有错误但没有显示广告
@Suppress("DEPRECATION")
class ResultActivity : AppCompatActivity()
private var mRewardedAd: RewardedAd? = null
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_result)
// TODO (STEP 6: Hide the status bar and get the details from intent and set it to the UI. And also add a click event to the finish button.)
// START
// Hide the status bar.
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
val adRequest = AdRequest.Builder().build()
RewardedAd.load(
this,
"ca-app-pub-5757320647",
adRequest,
object : RewardedAdLoadCallback()
override fun onAdFailedToLoad(adError: LoadAdError)
mRewardedAd = null
override fun onAdLoaded(rewardedAd: RewardedAd)
mRewardedAd = rewardedAd
mRewardedAd?.fullScreenContentCallback =
object : FullScreenContentCallback()
)
val userName = intent.getStringExtra(Constants.USER_NAME)
tv_name.text = userName
val totalQuestions = intent.getIntExtra(Constants.TOTAL_QUESTIONS, 0)
val correctAnswers = intent.getIntExtra(Constants.CORRECT_ANSWERS, 0)
tv_score.text = "Your Score is $correctAnswers out of $totalQuestions."
btn_finish.setOnClickListener
mRewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback()
startActivity(Intent(this, MainActivity::class.java))
**我的代码有什么问题吗**
enter image description here
enter image description here
【问题讨论】:
【参考方案1】:在调用加载奖励广告的请求后,您正在启动一项活动,该广告将显示活动而不是广告,因为广告无法在后台播放。而是查看this 并在onAdDismissedFullScreenContent
中调用startActivity
。
编辑:- 试试这个
mRewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback()
override fun onAdDismissedFullScreenContent()
startActivity(Intent(this, MainActivity::class.java))
override fun onAdFailedToShowFullScreenContent(adError: AdError)
startActivity(Intent(this, MainActivity::class.java))
override fun onAdImpression()
startActivity(Intent(this, MainActivity::class.java))
override fun onAdShowedFullScreenContent()
startActivity(Intent(this, MainActivity::class.java))
【讨论】:
mRewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback() startActivity(Intent(this, MainActivity::class.java)) //像这样? 没有。像这样mRewardedAd?.fullScreenContentCallback = object: FullScreenContentCallback() startActivity(Intent(this, MainActivity::class.java))
帖子中的图片
使用 this@ResultActivity.startActivity
还是同样的问题,再次查看我更新的帖子以上是关于admob 改写广告不显示 kotlin的主要内容,如果未能解决你的问题,请参考以下文章
Admob 测试广告不起作用,只有真实的广告在显示 - Android